mirror of
https://github.com/EvernodeXRPL/hpcore.git
synced 2026-07-24 15:40:34 +00:00
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.
This commit is contained in:
23
src/conf.cpp
23
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<std::string>();
|
||||
const std::unordered_set<std::string> 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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user