diff --git a/src/bin/calaos_server/Audio/AVRRose.cpp b/src/bin/calaos_server/Audio/AVRRose.cpp index 5b63ca94..4b9e121d 100644 --- a/src/bin/calaos_server/Audio/AVRRose.cpp +++ b/src/bin/calaos_server/Audio/AVRRose.cpp @@ -152,6 +152,8 @@ void AVRRose::postRequest(string urlPath, string data, std::functionsetHeader("Content-Type", "application/json"); dl->httpPost({}, data); diff --git a/src/bin/calaos_server/WebSocket.cpp b/src/bin/calaos_server/WebSocket.cpp index c566153e..df76364e 100644 --- a/src/bin/calaos_server/WebSocket.cpp +++ b/src/bin/calaos_server/WebSocket.cpp @@ -443,7 +443,7 @@ void WebSocket::processControlFrame() if (status == WSClosing) return; double elapsed = Utils::getMainLoopTime() - ping_time; - cInfoDom("websocket") << "Received a PONG back in " << Utils::time2string_digit(elapsed, elapsed * 1000.); + cDebugDom("websocket") << "Received a PONG back in " << Utils::time2string_digit(elapsed, elapsed * 1000.); } else if (currentFrame.isCloseFrame()) { @@ -452,7 +452,7 @@ void WebSocket::processControlFrame() string close_reason; currentFrame.parseCloseCodeReason(code, close_reason); - cInfoDom("websocket") << "Close frame received, code:" << code << " reason: " << close_reason; + cDebugDom("websocket") << "Close frame received, code:" << code << " reason: " << close_reason; DELETE_NULL(closeTimeout); closeReceived = true; diff --git a/src/lib/Logger.cpp b/src/lib/Logger.cpp index 3964d04d..959bfae8 100644 --- a/src/lib/Logger.cpp +++ b/src/lib/Logger.cpp @@ -73,29 +73,74 @@ bool LogStream::isTerminal() * LOG_LEVEL_WARNING = 3 * LOG_LEVEL_INFO = 4 * LOG_LEVEL_DEBUG = 5 + * + * To configure log levels per domain, use: + * calaos_config set debug_domains hifirose:5,network:0 + * + * To set default log level for all non-specified domains, use: + * calaos_config set debug_level 3 + * */ -static int maxLevelPrintable() +static int maxLevelPrintable(string domain) { - static int max_level_print = -1; + static std::unordered_map logger_domains; - if (max_level_print > -1) - return max_level_print; - - string lvl = Utils::get_config_option("debug_level"); - if (Utils::is_of_type(lvl)) - Utils::from_string(lvl, max_level_print); + if (logger_domains.empty()) + { + int logger_default_level = Logger::LOG_LEVEL_INFO; + string lvl = Utils::get_config_option("debug_level"); + if (Utils::is_of_type(lvl)) + Utils::from_string(lvl, logger_default_level); + + if (logger_default_level < Logger::LOG_LEVEL_UNKNOWN || + logger_default_level > Logger::LOG_LEVEL_DEBUG) + logger_default_level = Logger::LOG_LEVEL_INFO; + + //default logger level for all non-specified domains + logger_domains["default"] = logger_default_level; + + string domains = Utils::get_config_option("debug_domains"); + if (!domains.empty()) + { + std::vector parts; + Utils::split(domains, parts, ","); + + for (const auto &d: parts) + { + std::vector dp; + Utils::split(d, dp, ":"); + + if (dp.size() == 2) + { + int l; + if (Utils::is_of_type(dp[1])) + { + Utils::from_string(dp[1], l); + if (l >= Logger::LOG_LEVEL_UNKNOWN && l <= Logger::LOG_LEVEL_DEBUG) + logger_domains[dp[0]] = l; + } + } + } + } + + if (logger_default_level == Logger::LOG_LEVEL_DEBUG) + { + for (const auto &d: logger_domains) + cDebug() << "Logger: Domain: " << d.first << " Level: " << d.second; + } + } - if (max_level_print < 0 || - max_level_print > Logger::LOG_LEVEL_DEBUG) - max_level_print = Logger::LOG_LEVEL_INFO; + auto it = logger_domains.find(domain); + if (it != logger_domains.end()) + return it->second; - return max_level_print; + return logger_domains["default"]; } LogStream::~LogStream() { - if (logData->level > maxLevelPrintable()) + if (logData->level > maxLevelPrintable(logData->domain)) return; //Strip away file path and only keep filename