From b525498d3951edeaf5d8255411efab4f5604b2f9 Mon Sep 17 00:00:00 2001 From: rippleitinnz Date: Tue, 19 May 2026 16:13:24 +1200 Subject: [PATCH] fix: dynamic log level update from patch.cfg without container restart When log.log_level is present in patch.cfg, apply_patch_config() now updates the live plog logger severity via plog::get()->setMaxSeverity() in addition to persisting the change to hp.cfg and the runtime cfg struct. Previously log level was only read at startup (hplog::init()) and could not be changed on a running node without a container restart. This meant operators had no way to change log verbosity on external Evernode hosts where they don't control the container lifecycle. The fix uses plog's built-in setMaxSeverity() API which is thread-safe and takes effect immediately on the next log statement. --- src/conf.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/conf.cpp b/src/conf.cpp index 47e6e696..0acae924 100644 --- a/src/conf.cpp +++ b/src/conf.cpp @@ -853,6 +853,29 @@ namespace conf return -1; } + // Apply log level change dynamically if present in patch config. + // Uses plog::get()->setMaxSeverity() to update the live logger without restart. + try { + if (jdoc.contains("log") && jdoc["log"].contains("log_level")) { + const std::string new_log_level = jdoc["log"]["log_level"].as(); + const std::unordered_set valid_loglevels({"dbg", "inf", "wrn", "err"}); + if (valid_loglevels.count(new_log_level) == 1) { + cfg.log.log_level = new_log_level; + cfg.log.log_level_type = get_loglevel_type(new_log_level); + temp_cfg.log.log_level = new_log_level; + temp_cfg.log.log_level_type = get_loglevel_type(new_log_level); + plog::Severity new_plog_level; + if (cfg.log.log_level_type == LOG_SEVERITY::DEBUG) new_plog_level = plog::Severity::debug; + else if (cfg.log.log_level_type == LOG_SEVERITY::INFO) new_plog_level = plog::Severity::info; + else if (cfg.log.log_level_type == LOG_SEVERITY::WARN) new_plog_level = plog::Severity::warning; + else new_plog_level = plog::Severity::error; + plog::get()->setMaxSeverity(new_plog_level); + LOG_INFO << "Log level updated dynamically to: " << new_log_level; + } + } + } catch (const std::exception &e) { + LOG_ERROR << "Error applying log level from patch config: " << e.what(); + } LOG_INFO << "Contract config updated from patch file."; return 0; }