mirror of https://github.com/Icinga/icinga2.git
parent
2989c00680
commit
17668af2c2
|
@ -429,7 +429,16 @@ int Main(void)
|
|||
#endif /* _WIN32 */
|
||||
|
||||
if (g_AppParams.count("log-level")) {
|
||||
LogSeverity logLevel = Logger::StringToSeverity(g_AppParams["log-level"].as<std::string>());
|
||||
String severity = g_AppParams["log-level"].as<std::string>();
|
||||
|
||||
LogSeverity logLevel = LogInformation;
|
||||
try {
|
||||
logLevel = Logger::StringToSeverity(severity);
|
||||
} catch (std::exception&) {
|
||||
/* use the default */
|
||||
Log(LogWarning, "icinga", "Invalid log level set. Using default 'information'.");
|
||||
}
|
||||
|
||||
Logger::SetConsoleLogSeverity(logLevel);
|
||||
}
|
||||
|
||||
|
|
|
@ -123,8 +123,15 @@ LogSeverity Logger::GetMinSeverity(void) const
|
|||
String severity = GetSeverity();
|
||||
if (severity.IsEmpty())
|
||||
return LogInformation;
|
||||
else
|
||||
return Logger::StringToSeverity(severity);
|
||||
else {
|
||||
LogSeverity ls = LogInformation;
|
||||
|
||||
try {
|
||||
ls = Logger::StringToSeverity(severity);
|
||||
} catch (std::exception&) { /* use the default level */ }
|
||||
|
||||
return ls;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -146,6 +153,7 @@ String Logger::SeverityToString(LogSeverity severity)
|
|||
case LogCritical:
|
||||
return "critical";
|
||||
default:
|
||||
Log(LogCritical, "Logger", "Invalid severity.");
|
||||
BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid severity."));
|
||||
}
|
||||
}
|
||||
|
@ -167,8 +175,10 @@ LogSeverity Logger::StringToSeverity(const String& severity)
|
|||
return LogWarning;
|
||||
else if (severity == "critical")
|
||||
return LogCritical;
|
||||
else
|
||||
else {
|
||||
Log(LogCritical, "Logger", "Invalid severity: '" + severity + "'.");
|
||||
BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid severity: " + severity));
|
||||
}
|
||||
}
|
||||
|
||||
void Logger::DisableConsoleLog(void)
|
||||
|
@ -189,4 +199,4 @@ void Logger::SetConsoleLogSeverity(LogSeverity logSeverity)
|
|||
LogSeverity Logger::GetConsoleLogSeverity(void)
|
||||
{
|
||||
return m_ConsoleLogSeverity;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -114,7 +114,12 @@ void StreamLogger::ProcessLogEntry(std::ostream& stream, bool tty, const LogEntr
|
|||
}
|
||||
}
|
||||
|
||||
stream << Logger::SeverityToString(entry.Severity);
|
||||
try {
|
||||
stream << Logger::SeverityToString(entry.Severity);
|
||||
} catch (std::exception&) {
|
||||
/* bail early */
|
||||
return;
|
||||
}
|
||||
|
||||
if (tty)
|
||||
stream << "\x1b[0m"; // clear colors
|
||||
|
|
Loading…
Reference in New Issue