Skip to content

Commit

Permalink
Log: Set log level via environment
Browse files Browse the repository at this point in the history
If the BTOP_LOG_LEVEL is found in the environment it is parsed and
overwrites the current configured log level. The --debug switch still
has precedence

The value of BTOP_LOG_LEVEL must match one of `Logger::log_levels`
fields, being case insensitive
  • Loading branch information
imwints committed Sep 10, 2023
1 parent 5b4ed12 commit 756319d
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/btop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -804,19 +804,27 @@ int main(int argc, char **argv) {
}

//? Config init
{ vector<string> load_warnings;
{
vector<string> load_warnings;
Config::load(Config::conf_file, load_warnings);

if (Config::current_boxes.empty()) Config::check_boxes(Config::getS("shown_boxes"));
Config::set("lowcolor", (Global::arg_low_color ? true : not Config::getB("truecolor")));

const auto log_level_env = Tools::str_to_upper(std::getenv("BTOP_LOG_LEVEL"));
if (Global::debug) {
Logger::set("DEBUG");
Logger::debug("Starting in DEBUG mode!");
}
else Logger::set(Config::getS("log_level"));
else if (v_contains(Logger::log_levels, log_level_env)) {
Logger::set(log_level_env);
Logger::info("Logger set to {}", log_level_env);
}
else {
Logger::set(Config::getS("log_level"));
Logger::info("Logger set to {}", Config::getS("log_level"));
}

Logger::info("Logger set to {}", (Global::debug ? "DEBUG" : Config::getS("log_level")));

for (const auto& err_str : load_warnings) Logger::warning("{}", err_str);
}
Expand Down

0 comments on commit 756319d

Please sign in to comment.