mirror of
https://github.com/aristocratos/btop.git
synced 2024-06-02 02:24:54 +12:00
Set log level via environment variable
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
This commit is contained in:
parent
310d96443c
commit
3c92f2b912
|
@ -1053,6 +1053,13 @@ optional arguments:
|
|||
and screen draw functions and sets loglevel to DEBUG
|
||||
```
|
||||
|
||||
It's also possible to specify a log level using the `BTOP_LOG_LEVEL` environment variable.
|
||||
It takes the same values as the `log_level` configuation option + "DISABLED", being case insensitive.
|
||||
```bash
|
||||
BTOP_LOG_LEVEL=info btop
|
||||
```
|
||||
will launch btop with the info logging level.
|
||||
|
||||
## LICENSE
|
||||
|
||||
[Apache License 2.0](LICENSE)
|
||||
|
|
21
src/btop.cpp
21
src/btop.cpp
|
@ -880,19 +880,32 @@ 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")));
|
||||
|
||||
std::string log_level_env {};
|
||||
{
|
||||
char* log_env = std::getenv("BTOP_LOG_LEVEL");
|
||||
if (log_env != nullptr) {
|
||||
log_level_env = Tools::str_to_upper(log_env);
|
||||
}
|
||||
}
|
||||
if (Global::debug) {
|
||||
Logger::set("DEBUG");
|
||||
Logger::debug("Starting in DEBUG mode!");
|
||||
}
|
||||
else Logger::set(Config::getS("log_level"));
|
||||
|
||||
Logger::info("Logger set to {}", (Global::debug ? "DEBUG" : Config::getS("log_level")));
|
||||
else if (v_contains(Logger::log_levels, log_level_env)) {
|
||||
Logger::set(log_level_env);
|
||||
Logger::info("Log level set to {}", log_level_env);
|
||||
}
|
||||
else {
|
||||
Logger::set(Config::getS("log_level"));
|
||||
Logger::info("Log level set to {}", Config::getS("log_level"));
|
||||
}
|
||||
|
||||
for (const auto& err_str : load_warnings) Logger::warning("{}", err_str);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue