Simplify MANGOHUD_LOG_LEVEL TO SPDLOG_LEVEL
@@ -78,26 +78,16 @@ void init_spdlog()
#endif
spdlog::cfg::load_env_levels();
- const char* log_level = getenv("MANGOHUD_LOG_LEVEL");
- if (log_level) {
- std::string level = log_level;
- if( level == "off" || level == "OFF" ) {
- spdlog::set_level(spdlog::level::level_enum::off);
+ // Use MANGOHUD_LOG_LEVEL to correspond to SPDLOG_LEVEL
+ if (getenv("MANGOHUD_LOG_LEVEL")) {
+ std::string log_level = getenv("MANGOHUD_LOG_LEVEL");
+ vector<string> levels;
+ levels = {"off","OFF","info","INFO","err","ERR","debug","DEBUG"};
+ for (auto & element : levels) {
+ transform(log_level.begin(), log_level.end(), log_level.begin(), ::tolower);
+ if(log_level == element ) {
+ spdlog::set_level(spdlog::level::from_str(log_level));
}
- else if( level == "info" || level == "INFO" ) {
- spdlog::set_level(spdlog::level::level_enum::info);
- }
- else if( level == "err" || level == "ERR" ) {
- spdlog::set_level(spdlog::level::level_enum::err);
- }
- else if( level == "warn" || level == "WARN" ) {
- spdlog::set_level(spdlog::level::level_enum::warn);
- }
- else if( level == "debug" || level == "DEBUG") {
- spdlog::set_level(spdlog::level::level_enum::debug);
- }
- else {
- SPDLOG_ERROR("'{}' is not a valid log_level", level);
}
}
