diff --git a/src/BasicChannel.cpp b/src/BasicChannel.cpp index a3c30d9..59652e1 100644 --- a/src/BasicChannel.cpp +++ b/src/BasicChannel.cpp @@ -203,11 +203,11 @@ std::shared_ptr BasicChannelTree::findChannelByPath(const std::str index = found + 1; } while (index != 0 && entries.size() <= maxChannelDeep); - debugMessage("Parsed channel path '" + path + "'. Entries:"); + debugMessage(LOG_GENERAL, "Parsed channel path \"{}\". Entries:", path); std::shared_ptr current = nullptr; for (const auto &name : entries) { current = this->findChannel(name, current); - debugMessage(" - '" + name + "' (" + (current ? "found" : "unknown") + ")"); + debugMessage(LOG_GENERAL, " - \"{}\" {}", name, (current ? "found" : "unknown")); if (!current) break; } return current; diff --git a/src/log/LogSinks.cpp b/src/log/LogSinks.cpp index 7d5641e..53640a5 100644 --- a/src/log/LogSinks.cpp +++ b/src/log/LogSinks.cpp @@ -1,118 +1,119 @@ #include "LogUtils.h" #include "LogSinks.h" -#include #include -#include -#include +#include using namespace std; using namespace spdlog; -namespace fs = std::experimental::filesystem; namespace logger { - void TerminalSink::log(const spdlog::details::log_msg &msg) { -#ifdef HAVE_CXX_TERMINAL - if (terminal::active()) { - auto strMsg = msg.formatted.str(); - size_t index = 0; - do { - auto eIndex = strMsg.find('\n', index); - auto str = terminal::parseCharacterCodes(strMsg.substr(index, eIndex - index)); - terminal::instance()->writeMessage(str); - index = eIndex + 1; - } while (index != 0 && index < strMsg.length()); //if eindex == npos and we add the 1 we get 0 :) - } else -#endif - cout << msg.formatted.str(); - } + void TerminalSink::sink_it_(const spdlog::details::log_msg &msg) { + memory_buf_t formatted; + this->formatter_->format(msg, formatted); - void TerminalSink::flush() {} + std::string_view message{formatted.data(), formatted.size()}; - bool TerminalSink::should_log_(const details::log_msg &msg) const { - auto _force_message = dynamic_cast(&msg); - if(_force_message && _force_message->force) - return true; - return sink::should_log_(msg); - } + #ifdef HAVE_CXX_TERMINAL + if (terminal::active()) { + //Split the string at new lines + size_t index{0}, found{0}; + do { + found = message.find('\n', index); + const auto length = (found == -1 ? message.length() : found) - index; + const auto line = message.substr(index, length); - ColoredFileSink::ColoredFileSink(const filename_t &base_filename, size_t max_size, size_t max_files) - : rotating_file_sink( - base_filename, max_size, max_files) {} + index = found; + if(length == 0) continue; - void ColoredFileSink::_sink_it(const details::log_msg &msg) { - details::log_msg _clone; + terminal::instance()->writeMessage(std::string{line}); + } while(++index); + } else + #endif + cout << message; + } -#ifdef HAVE_CXX_TERMINAL - if (::logger::currentConfig()->file_colored) - _clone.formatted << ANSI_RESET << terminal::parseCharacterCodes(msg.formatted.str()); - else - _clone.formatted << terminal::stripCharacterCodes(msg.formatted.str()); -#else - _clone.formatted << msg.formatted.str(); -#endif - sinks::rotating_file_sink_mt::_sink_it(_clone); - } + void TerminalSink::flush_() {} - void CostumeFormatter::format(spdlog::details::log_msg &msg) { - msg.formatted.clear(); - string lvlName = level::to_str(msg.level); - transform(lvlName.begin(), lvlName.end(), lvlName.begin(), ::toupper); - auto org_length = lvlName.length(); + inline void append_time(const log_clock::time_point& point, memory_buf_t& dest) { + std::time_t time = log_clock::to_time_t(point); + std::tm timetm = *std::localtime(&time); - string msgColor; - string msgSuffix; -#ifdef HAVE_CXX_TERMINAL - switch (msg.level) { - case level::trace: - lvlName = "§9" + lvlName; - break; - case level::info: - lvlName = "§e" + lvlName; - break; - case level::warn: - lvlName = "§6" + lvlName; - break; - case level::err: - lvlName = "§4" + lvlName; - break; - case level::critical: - lvlName = ANSI_BOLD ANSI_REVERSE ANSI_RED + lvlName; - msgColor = ANSI_BOLD ANSI_REVERSE ANSI_RED; - msgSuffix = ANSI_RESET; - break; - case level::debug: - lvlName = "§9" + lvlName; - break; - default: - break; - } -#endif + static constexpr auto max_length = 9; + dest.reserve(dest.size() + max_length); - auto strMsg = msg.raw.str(); + auto length = strftime(dest.end(), max_length, "%H:%M:%S", &timetm); + if(length < 0) + length = 0; - auto tp = std::chrono::system_clock::to_time_t(msg.time); + dest.resize(dest.size() + length); + } - stringstream prefix; - prefix << "[" << std::put_time(std::localtime(&tp), "%F %T") << "] [" << lvlName << "§r] "; - for(size_t i = org_length; i < 5; i++) - prefix << " "; - prefix << msgColor; + static constexpr std::array level_mapping_colored{ + " [" ANSI_LIGHT_BLUE "TRACE" ANSI_RESET "] ", + " [" ANSI_LIGHT_BLUE "DEBUG" ANSI_RESET "] ", + " [" ANSI_YELLOW "INFO " ANSI_RESET "] ", + " [" ANSI_BROWN "WARNING " ANSI_RESET "] ", + " [" ANSI_RED "ERROR" ANSI_RESET "] ", + " [" ANSI_RED ANSI_BOLD ANSI_REVERSE "CRITICAL" ANSI_RESET "] ", + " [" ANSI_GRAY "OFF " ANSI_RESET "] " + }; - size_t index = 0; - do { - auto eIndex = strMsg.find('\n', index); - auto m = strMsg.substr(index, eIndex - index); - msg.formatted << "§r" << prefix.str() << m << msgSuffix << "\n"; - index = eIndex + 1; //if eindex == npos and we add the 1 we get 0 :) - } while (index != 0 && index < strMsg.length()); - } + static constexpr std::array level_mapping{ + " [TRACE] ", + " [DEBUG] ", + " [INFO ] ", + " [WARNING ] ", + " [ERROR] ", + " [CRITICAL] ", + " [OFF ] " + }; - inline std::string CostumeFormatter::time(chrono::time_point point) { - std::time_t time = log_clock::to_time_t(point); - std::tm timetm = *std::localtime(&time); - char buffer[9]; - strftime(buffer, 9, "%H:%M:%S", &timetm); - return string(buffer, 8); - } + void LogFormatter::format(const details::log_msg &msg, memory_buf_t &dest) { + const auto append = [&](const std::string_view& message) { dest.append(message.begin(), message.end()); }; + + dest.clear(); + auto prefix_begin = dest.end(); + //Time + { + dest.push_back('['); + append_time(msg.time, dest); + dest.push_back(']'); + } + + //Level + { + const auto& mapping = this->_colored ? level_mapping_colored : level_mapping; + + size_t level = msg.level.value; + if(level >= mapping.size()) + level = mapping.size() - 1; + + append(mapping[level]); + } + auto prefix_end = dest.end(); + + //Append the prefix to every line + std::string_view payload{msg.payload.data(), msg.payload.size()}; + size_t index{0}, found{0}; + while(true) { + found = payload.find(spdlog::details::os::default_eol, index); + auto line = payload.substr(index, (found == -1 ? payload.length() : found) - index); + + auto colored = this->_colored ? terminal::parseCharacterCodes(std::string{line}) : terminal::stripCharacterCodes(std::string{line}); + dest.append(colored.data(), colored.data() + colored.size()); + + index = found; + + append(spdlog::details::os::default_eol); + if(++index) + dest.append(prefix_begin, prefix_end); + else + break; + } + } + + [[nodiscard]] std::unique_ptr LogFormatter::clone() const { + return std::make_unique(this->_colored); + } } \ No newline at end of file diff --git a/src/log/LogSinks.h b/src/log/LogSinks.h index 7bafcd9..8474499 100644 --- a/src/log/LogSinks.h +++ b/src/log/LogSinks.h @@ -1,50 +1,37 @@ #pragma once -#define SPDLOG_FINAL -#define SPDLOG_ALLOW_PROTECT -#define SPDLOG_NO_FINAL //We need to override the rotating logger - #include -#include +#include namespace logger { - struct force_log_msg : public spdlog::details::log_msg - { - force_log_msg() = default; - virtual ~force_log_msg() = default; - force_log_msg(const std::string *loggers_name, spdlog::level::level_enum lvl, bool force) : log_msg(loggers_name, lvl), force(force) { } + class ColorCodeFormatter : public spdlog::formatter { + public: + void format(const spdlog::details::log_msg &msg, spdlog::memory_buf_t &dest) override { + dest.append(msg.payload.begin(), msg.payload.end()); + } - force_log_msg(const log_msg& other) = delete; - force_log_msg(log_msg&& other) = delete; - force_log_msg(const force_log_msg& other) = delete; - force_log_msg& operator=(force_log_msg&& other) = delete; - force_log_msg(force_log_msg&& other) = delete; + [[nodiscard]] std::unique_ptr clone() const override { + return std::unique_ptr(); + } + }; - - bool force; - }; - - class TerminalSink : public spdlog::sinks::sink { + //TODO: Mutex really needed here? + class TerminalSink : public spdlog::sinks::base_sink { public: - void log(const spdlog::details::log_msg &msg) override; - void flush(); - - bool should_log_(const spdlog::details::log_msg &msg) const override; + void sink_it_(const spdlog::details::log_msg &msg) override; + void flush_() override; }; - class ColoredFileSink : public spdlog::sinks::rotating_file_sink_mt { - public: - ColoredFileSink(const spdlog::filename_t &base_filename, size_t max_size, size_t max_files); + class LogFormatter : public spdlog::formatter { + public: + explicit LogFormatter(bool colored) : _colored{colored} {} - protected: - void _sink_it(const spdlog::details::log_msg &msg) override; - }; + void format(const spdlog::details::log_msg &msg, spdlog::memory_buf_t &dest) override; + [[nodiscard]] std::unique_ptr clone() const override; - class CostumeFormatter : public spdlog::formatter { - public: - void format(spdlog::details::log_msg &msg) override; - - private: - inline std::string time(std::chrono::time_point point); - }; + inline bool colored() const { return this->_colored; } + inline void colored(bool flag) { this->_colored = flag; } + private: + bool _colored{true}; + }; } diff --git a/src/log/LogUtils.cpp b/src/log/LogUtils.cpp index dbf53c0..559b5bc 100644 --- a/src/log/LogUtils.cpp +++ b/src/log/LogUtils.cpp @@ -4,11 +4,14 @@ #include #include #include -#include #include #include #include +#include +#include +#include + using namespace std; using namespace std::chrono; using namespace spdlog; @@ -20,11 +23,71 @@ namespace logger { map> loggers; shared_ptr logConfig; shared_ptr<::logger::TerminalSink> terminalSink; - shared_ptr<::logger::CostumeFormatter> costumeFormatter; + + std::shared_ptr logging_threads{nullptr}; + + spdlog::level::level_enum min_level{spdlog::level::trace}; + + void updater_logger_levels(const std::shared_ptr& logger) { + for(const auto& sink : logger->sinks()) + if(dynamic_pointer_cast(sink)) { + sink->set_level(::logger::currentConfig()->terminalLevel); + } else if(dynamic_pointer_cast(sink)) { + sink->set_level(::logger::currentConfig()->logfileLevel); + } else if(dynamic_pointer_cast(sink)) { + sink->set_level(::logger::currentConfig()->logfileLevel); + } else { + sink->set_level(min_level); + } + logger->set_level(min_level); + } + + std::string generate_log_file(int group) { + return strvar::transform(logConfig->logPath, + strvar::StringValue{"group", group != -1 ? to_string(group) : "general"}, + strvar::FunctionValue("time", (strvar::FunctionValue::FValueFNEasy) [](std::deque value) -> std::string { + auto pattern = !value.empty() ? value[0] : "%Y-%m-%d_%H:%M:%S"; + + auto secs = duration_cast(logConfig->timestamp.time_since_epoch()).count(); + tm* tm_info; +#ifdef WIN32 + tm _tm_info{}; + localtime_s(&_tm_info, &secs); + tm_info = &_tm_info; +#else + tm_info = localtime((time_t*) &secs); +#endif + char timeBuffer[1024]; + if(strftime(timeBuffer, 1024, pattern.c_str(), tm_info) == 0) { + return string("string is longer than the buffer"); + } + + return string(timeBuffer); + }) + ); + } + + std::mutex default_lock{}; + bool default_setup{false}; + + std::shared_ptr default_logger() { + lock_guard lock{default_lock}; + if(!default_setup) { + default_setup = true; + + spdlog::default_logger()->sinks().clear(); + auto terminal_sink = make_shared(); + terminal_sink->set_level(spdlog::level::trace); + spdlog::default_logger()->sinks().push_back(terminal_sink); + + spdlog::default_logger()->set_formatter(std::make_unique(true)); + } + return spdlog::default_logger(); + } shared_ptr logger(int serverId) { if(!::logger::currentConfig()) - return nullptr; + return default_logger(); size_t group = 0; if(::logger::currentConfig()->vs_group_size > 0 && serverId > 0) @@ -41,35 +104,16 @@ namespace logger { vector sinks; string path; if(logConfig->logfileLevel != spdlog::level::off) { - path = strvar::transform(logConfig->logPath, - strvar::StringValue{"group", group != -1 ? to_string(group) : "general"}, - strvar::FunctionValue("time", (strvar::FunctionValue::FValueFNEasy) [](std::deque value) -> std::string { - auto pattern = !value.empty() ? value[0] : "%Y-%m-%d_%H:%M:%S"; + path = generate_log_file(group); - auto secs = duration_cast(logConfig->timestamp.time_since_epoch()).count(); - tm* tm_info; -#ifdef WIN32 - tm _tm_info{}; - localtime_s(&_tm_info, &secs); - tm_info = &_tm_info; -#else - tm_info = localtime((time_t*) &secs); -#endif - char timeBuffer[1024]; - if(strftime(timeBuffer, 1024, pattern.c_str(), tm_info) == 0) { - return string("string is longer than the buffer"); - } - - return string(timeBuffer); - }) - ); auto logFile = fs::u8path(path); if(!logFile.parent_path().empty()) fs::create_directories(logFile.parent_path()); try { - auto fileSink = make_shared(logFile.string(), 1024 * 1024 * 50, 12); - sinks.push_back(fileSink); + auto sink = make_shared(logFile.string(), 1024 * 1024 * 50, 12); + sink->set_formatter(std::make_unique(::logger::currentConfig()->file_colored)); + sinks.push_back(sink); } catch(std::exception& ex) { if(group != 0 && group != -1) logger(0)->critical("Failed to create file for new log group: {}", ex.what()); @@ -77,25 +121,19 @@ namespace logger { terminal::instance()->writeMessage("§4[CRITICAL] §eFailed to create main log file: " + string{ex.what()}, false); } } else { - path = "/dev/null (" + to_string(serverId) + ")"; + path = "/dev/null (" + to_string(group) + ")"; } sinks.push_back(terminalSink); + if(!logging_threads) + logging_threads = std::make_shared(8192, 1); //Only one thread possible here, else elements get reordered #ifdef ASYNC_LOG - auto logger = create_async("Logger (" + path + ")", sinks.begin(), sinks.end(), 8192, async_overflow_policy::discard_log_msg, [](){}, std::chrono::milliseconds(500)); + auto logger = std::make_shared("Logger (" + path + ")", sinks.begin(), sinks.end(), logging_threads, async_overflow_policy::block); #else + //FIXME! auto logger = create("Logger (" + path + ")", sinks.begin(), sinks.end()); #endif - logger->set_formatter(costumeFormatter); - for(const auto& sink : logger->sinks()) - if(dynamic_pointer_cast(sink)) { - sink->set_level(::logger::currentConfig()->terminalLevel); - } else if(dynamic_pointer_cast(sink)) { - sink->set_level(::logger::currentConfig()->logfileLevel); - } else { - sink->set_level(min(::logger::currentConfig()->logfileLevel, ::logger::currentConfig()->terminalLevel)); - } - logger->set_level(min(::logger::currentConfig()->logfileLevel, ::logger::currentConfig()->terminalLevel)); + updater_logger_levels(logger); loggers[group] = logger; } @@ -112,22 +150,63 @@ namespace logger { terminalSink = make_shared(); terminalSink->set_level(::logger::currentConfig()->terminalLevel); - costumeFormatter = make_shared(); + terminalSink->set_formatter(std::make_unique(true)); + min_level = ::min(::logger::currentConfig()->logfileLevel, ::logger::currentConfig()->terminalLevel); + logger(0)->debug("Log successfully started!"); } + + bool should_log(spdlog::level::level_enum level) { + return level >= min_level; + } + + void log(spdlog::level::forceable level, int server_id, const std::string_view& buffer) { + auto logger = ::logger::logger(server_id); + + auto message_format = "§8{0:>5} | §r{1}"; + if(server_id <= 0) { + switch (server_id) { + case LOG_INSTANCE: + message_format = "§8GLOBL | §r{1}"; + break; + case LOG_QUERY: + message_format = "§8QUERY | §r{1}"; + break; + case LOG_FT: + message_format = "§8 FILE | §r{1}"; + break; + case LOG_GENERAL: + message_format = "§8 GEN | §r{1}"; + break; + case LOG_LICENSE_CONTROLL: + message_format = "§8 CONTR | §r{1}"; + break; + case LOG_LICENSE_WEB: + message_format = "§8 WEBST | §r{1}"; + break; + + default: + break; + } + } + + try { + logger->log(level, message_format, server_id, buffer); + } catch (const std::exception &ex) { + //TODO better? + std::cerr << "An exception has raised while logging a message (" << ex.what() << "): " << buffer << "\n"; + } catch(...) { + std::cerr << "An unknown exception has raised while logging a message: " << buffer << "\n"; + throw; + } + } + void updateLogLevels() { lock_guard lock(loggerLock); - for(const auto& loggerEntry : loggers) { - auto logger = loggerEntry.second; - for(const auto& sink : logger->sinks()) - if(dynamic_pointer_cast(sink)) - sink->set_level(::logger::currentConfig()->terminalLevel); - else if(dynamic_pointer_cast(sink)) - sink->set_level(::logger::currentConfig()->logfileLevel); - else - sink->set_level(min(::logger::currentConfig()->logfileLevel, ::logger::currentConfig()->terminalLevel)); - logger->set_level(min(::logger::currentConfig()->logfileLevel, ::logger::currentConfig()->terminalLevel)); + min_level = ::min(::logger::currentConfig()->logfileLevel, ::logger::currentConfig()->terminalLevel); + for(const auto& logger : loggers) { + updater_logger_levels(logger.second); } } @@ -152,7 +231,6 @@ namespace logger { logConfig = nullptr; terminalSink = nullptr; - costumeFormatter = nullptr; } } diff --git a/src/log/LogUtils.h b/src/log/LogUtils.h index 63fa90a..48ca3c7 100644 --- a/src/log/LogUtils.h +++ b/src/log/LogUtils.h @@ -1,28 +1,25 @@ #pragma once +#define SPDLOG_EOL "\n" #ifdef SPDLOG_FINAL #undef SPDLOG_FINAL #endif #define SPDLOG_FINAL -#define SPDLOG_ALLOW_PROTECT -#define SPDLOG_NO_FINAL //We need to override the rotating logger #ifdef byte #undef byte #endif #include +#include #include #include #include #include "../Definitions.h" -#include "LogSinks.h" #ifdef HAVE_CXX_TERMINAL #include #endif -#define lstream std::stringstream() - #ifdef log #undef log #endif @@ -41,8 +38,29 @@ namespace logger { extern const std::shared_ptr& currentConfig(); extern void uninstall(); + extern bool should_log(spdlog::level::level_enum /* level */); //TODO: inline? + extern void log(spdlog::level::forceable /* level */, int /* server id */, const std::string_view& /* buffer */); + extern void updateLogLevels(); extern void flush(); + + namespace impl { + template + inline void do_log(bool forced, int serverId, const std::string& message, const Args&... args) { + if(!forced && !::logger::should_log(level)) return; + spdlog::memory_buf_t buffer{}; + + auto _logger = ::logger::logger(serverId); + std::string fmt_message; + try { + fmt_message = fmt::format(message, args...); + } catch (const std::exception &ex) { + fmt_message = "failed to format message '" + std::string{message} + "': " + ex.what(); + } + + ::logger::log(spdlog::level::forceable{level, forced}, serverId, fmt_message); + } + } } #define LOG_LICENSE_CONTROLL (-0x10) @@ -53,59 +71,10 @@ namespace logger { #define LOG_FT (-3) #define LOG_GENERAL 0 -#ifdef HAVE_CXX_TERMINAL - #define DEFINE_LOG_IMPL_NO_LOGGER(prefix, message) \ - if(terminal::active()) \ - terminal::instance()->writeMessage("[" + std::string(prefix) + "] " + message); \ - else \ - std::cout << "[" + std::string(prefix) + "] " + message << std::endl; -#else - #define DEFINE_LOG_IMPL_NO_LOGGER(prefix, message) \ - std::cout << "[" + std::string(prefix) + "] " + message << std::endl; -#endif - -#define DEFINE_LOG_IMPL(name, level, _default_prefix) \ -template \ -inline void name ##Fmt(bool forced, int serverId, const std::string& message, const Args&... args){ \ - auto _logger = ::logger::logger(serverId); \ - std::string fmt_message; \ - try { \ - fmt::MemoryWriter writer; \ - writer.write(message, args...); \ - fmt_message = writer.str(); \ - } catch (const std::exception &ex) { \ - fmt_message = "failed to format message '" + message + "': " + ex.what(); \ - } \ - if(!_logger) { \ - DEFINE_LOG_IMPL_NO_LOGGER(_default_prefix, fmt_message); \ - return; \ - } \ - if (!_logger->should_log(level) && !forced) return; \ - \ - try { \ - ::logger::force_log_msg log_msg(&_logger->_name, level, forced); \ - auto fmt = "§8{0:>5} | §r{1}"; \ - if(serverId > 0); \ - else if(serverId == LOG_INSTANCE) \ - fmt = "§8GLOBL | §r{1}"; \ - else if(serverId == LOG_QUERY) \ - fmt = "§8QUERY | §r{1}"; \ - else if(serverId == LOG_FT) \ - fmt = "§8 FILE | §r{1}"; \ - else if(serverId == LOG_GENERAL) \ - fmt = "§8 GEN | §r{1}"; \ - else if(serverId == LOG_LICENSE_CONTROLL) \ - fmt = "§8 CONTR | §r{1}"; \ - else if(serverId == LOG_LICENSE_WEB) \ - fmt = "§8 WEBST | §r{1}"; \ - log_msg.raw.write(fmt, serverId, fmt_message); \ - _logger->_sink_it(log_msg); \ - } catch (const std::exception &ex) { \ - _logger->_err_handler(ex.what()); \ - } catch(...) { \ - _logger->_err_handler("Unknown exception in logger " + _logger->_name); \ - throw; \ - } \ +#define DEFINE_LOG_IMPL(name, level, _default_prefix) \ +template \ +inline void name ##Fmt(bool forced, int serverId, const std::string& message, const Args&... args) { \ + ::logger::impl::do_log(forced, serverId, message, args...); \ } DEFINE_LOG_IMPL(logMessage, spdlog::level::info, "INFO") @@ -119,9 +88,9 @@ DEFINE_LOG_IMPL(debugMessage, spdlog::level::debug, "DEBUG") template \ inline void name(int serverId, const std::string& message, const Args&... args){ name ##Fmt(false, serverId, message, args...); } \ inline void name(int serverId, const std::string& message){ name ##Fmt(false, serverId, message); } \ -inline void name(int serverId, std::ostream& str){ std::stringstream s; s << str.rdbuf(); name(serverId, s.str()); } \ -inline void name(const std::string& message) { name ##Fmt(false, 0, message); } \ -inline void name(std::ostream& str){ std::stringstream s; s << str.rdbuf(); name(s.str()); } \ +inline void name(int serverId, std::ostream& str) = delete; \ +inline void name(const std::string& message) = delete; \ +inline void name(std::ostream& str) = delete; \ inline void name(bool, int, const std::string&) = delete; LOG_METHOD(logError); diff --git a/src/misc/memtracker.cpp b/src/misc/memtracker.cpp index 64aeb1f..6218ec3 100644 --- a/src/misc/memtracker.cpp +++ b/src/misc/memtracker.cpp @@ -184,7 +184,7 @@ namespace memtrack { void statistics() { #ifdef NO_IMPL - logError("memtracker::statistics() does not work due compiler flags (NO_IMPL)"); + logError(LOG_GENERAL, "memtracker::statistics() does not work due compiler flags (NO_IMPL)"); return; #else map> objects; diff --git a/src/sql/SqlQuery.cpp b/src/sql/SqlQuery.cpp index e189856..75dbc39 100644 --- a/src/sql/SqlQuery.cpp +++ b/src/sql/SqlQuery.cpp @@ -21,7 +21,7 @@ namespace sql { } AsyncSqlPool::AsyncSqlPool(size_t threads) : _threads(new threads::ThreadPool(threads, "AsyncSqlPool")) { - debugMessage("Created a new async thread pool!"); + debugMessage(LOG_GENERAL, "Created a new async thread pool!"); } AsyncSqlPool::~AsyncSqlPool() { delete _threads; diff --git a/src/sql/SqlQuery.h b/src/sql/SqlQuery.h index c14adbb..bf8d529 100644 --- a/src/sql/SqlQuery.h +++ b/src/sql/SqlQuery.h @@ -13,7 +13,7 @@ #include #define ALLOW_STACK_ALLOCATION -#define LOG_SQL_CMD [](const sql::result &res){ if(!res) logCritical("Failed to execute sql command: " + std::to_string(res.code()) + "/" + res.msg() + " (" __FILE__ + ":" + to_string(__LINE__) + ")"); } +#define LOG_SQL_CMD [](const sql::result &res){ if(!res) logCritical(LOG_GENERAL, "Failed to execute sql command: " + std::to_string(res.code()) + "/" + res.msg() + " (" __FILE__ + ":" + to_string(__LINE__) + ")"); } namespace sql { class result; class SqlManager; diff --git a/src/ssl/SSLManager.cpp b/src/ssl/SSLManager.cpp index 9784896..5c9bd44 100644 --- a/src/ssl/SSLManager.cpp +++ b/src/ssl/SSLManager.cpp @@ -380,7 +380,7 @@ std::shared_ptr SSLManager::loadSSL(const std::string &key_data, std if(key_path.has_parent_path()) fs::create_directories(key_path.parent_path()); } catch (fs::filesystem_error& error) { - logError("Could not create key directory: " + string(error.what())); + logError(LOG_GENERAL, "Could not create key directory: " + string(error.what())); } {