mirror of https://github.com/Icinga/icinga2.git
parent
f88f23fa3b
commit
16a2d36bdc
|
@ -334,7 +334,7 @@ int Main(void)
|
|||
("config,c", po::value<std::vector<std::string> >(), "parse a configuration file")
|
||||
("no-config,z", "start without a configuration file")
|
||||
("validate,C", "exit after validating the configuration")
|
||||
("debug,x", po::value<std::string>(), "enable debugging with severity level specified")
|
||||
("log-level,x", po::value<std::string>(), "specify the log level for the console log")
|
||||
("errorlog,e", po::value<std::string>(), "log fatal errors to the specified log file (only works in combination with --daemonize)")
|
||||
#ifndef _WIN32
|
||||
("reload-internal", po::value<int>(), "used internally to implement config reload: do not call manually, send SIGHUP instead")
|
||||
|
@ -428,18 +428,9 @@ int Main(void)
|
|||
}
|
||||
#endif /* _WIN32 */
|
||||
|
||||
if (g_AppParams.count("debug")) {
|
||||
Application::SetDebugging(true);
|
||||
|
||||
LogSeverity debug_severity;
|
||||
try {
|
||||
debug_severity = Logger::StringToSeverity(g_AppParams["debug"].as<std::string>());
|
||||
} catch (std::exception&) {
|
||||
//not set, use default
|
||||
debug_severity = LogDebug;
|
||||
}
|
||||
|
||||
Application::SetDebuggingSeverity(debug_severity);
|
||||
if (g_AppParams.count("log-level")) {
|
||||
LogSeverity logLevel = Logger::StringToSeverity(g_AppParams["log-level"].as<std::string>());
|
||||
Logger::SetConsoleLogSeverity(logLevel);
|
||||
}
|
||||
|
||||
if (g_AppParams.count("help") || g_AppParams.count("version")) {
|
||||
|
|
|
@ -50,8 +50,6 @@ bool Application::m_RequestRestart = false;
|
|||
bool Application::m_RequestReopenLogs = false;
|
||||
pid_t Application::m_ReloadProcess = 0;
|
||||
static bool l_Restarting = false;
|
||||
bool Application::m_Debugging = false;
|
||||
LogSeverity Application::m_DebuggingSeverity = LogDebug;
|
||||
int Application::m_ArgC;
|
||||
char **Application::m_ArgV;
|
||||
double Application::m_StartTime;
|
||||
|
@ -75,11 +73,6 @@ void Application::OnConfigLoaded(void)
|
|||
}
|
||||
#endif /* _WIN32 */
|
||||
|
||||
#ifdef _WIN32
|
||||
if (IsDebuggerPresent())
|
||||
m_Debugging = true;
|
||||
#endif /* _WIN32 */
|
||||
|
||||
ASSERT(m_Instance == NULL);
|
||||
m_Instance = this;
|
||||
}
|
||||
|
@ -440,49 +433,6 @@ String Application::GetExePath(const String& argv0)
|
|||
#endif /* _WIN32 */
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether debugging is enabled.
|
||||
*
|
||||
* @param debug Whether to enable debugging.
|
||||
*/
|
||||
void Application::SetDebugging(bool debug)
|
||||
{
|
||||
m_Debugging = debug;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the debugging mode of the application.
|
||||
*
|
||||
* @returns true if the application is being debugged, false otherwise
|
||||
*/
|
||||
bool Application::IsDebugging(void)
|
||||
{
|
||||
return m_Debugging;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets debugging severity.
|
||||
*
|
||||
* @param severity Debug log severity.
|
||||
*/
|
||||
void Application::SetDebuggingSeverity(LogSeverity severity)
|
||||
{
|
||||
Application::m_DebuggingSeverity = severity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the debugging severity of the application.
|
||||
*
|
||||
* @returns severity 'debug' if not set, severity value otherwise.
|
||||
*/
|
||||
LogSeverity Application::GetDebuggingSeverity(void)
|
||||
{
|
||||
if (!Application::m_DebuggingSeverity)
|
||||
return LogDebug;
|
||||
|
||||
return Application::m_DebuggingSeverity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display version information.
|
||||
*/
|
||||
|
|
|
@ -69,9 +69,6 @@ public:
|
|||
static void RequestRestart(void);
|
||||
static void RequestReopenLogs(void);
|
||||
|
||||
static void SetDebugging(bool debug);
|
||||
static bool IsDebugging(void);
|
||||
|
||||
static void SetDebuggingSeverity(LogSeverity severity);
|
||||
static LogSeverity GetDebuggingSeverity(void);
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@ INITIALIZE_ONCE(&Logger::StaticInitialize);
|
|||
std::set<Logger::Ptr> Logger::m_Loggers;
|
||||
boost::mutex Logger::m_Mutex;
|
||||
bool Logger::m_ConsoleLogEnabled = true;
|
||||
LogSeverity Logger::m_ConsoleLogSeverity = LogInformation;
|
||||
|
||||
void Logger::StaticInitialize(void)
|
||||
{
|
||||
|
@ -105,14 +106,7 @@ void icinga::Log(LogSeverity severity, const String& facility,
|
|||
logger->ProcessLogEntry(entry);
|
||||
}
|
||||
|
||||
LogSeverity defaultLogLevel;
|
||||
|
||||
if (Application::IsDebugging())
|
||||
defaultLogLevel = Application::GetDebuggingSeverity();
|
||||
else
|
||||
defaultLogLevel = LogInformation;
|
||||
|
||||
if (Logger::IsConsoleLogEnabled() && entry.Severity >= defaultLogLevel) {
|
||||
if (Logger::IsConsoleLogEnabled() && entry.Severity >= Logger::GetConsoleLogSeverity()) {
|
||||
static bool tty = StreamLogger::IsTty(std::cout);
|
||||
|
||||
StreamLogger::ProcessLogEntry(std::cout, tty, entry);
|
||||
|
@ -187,3 +181,12 @@ bool Logger::IsConsoleLogEnabled(void)
|
|||
return m_ConsoleLogEnabled;
|
||||
}
|
||||
|
||||
void Logger::SetConsoleLogSeverity(LogSeverity logSeverity)
|
||||
{
|
||||
m_ConsoleLogSeverity = logSeverity;
|
||||
}
|
||||
|
||||
LogSeverity Logger::GetConsoleLogSeverity(void)
|
||||
{
|
||||
return m_ConsoleLogSeverity;
|
||||
}
|
|
@ -68,6 +68,9 @@ public:
|
|||
static void DisableConsoleLog(void);
|
||||
static bool IsConsoleLogEnabled(void);
|
||||
|
||||
static void SetConsoleLogSeverity(LogSeverity logSeverity);
|
||||
static LogSeverity GetConsoleLogSeverity(void);
|
||||
|
||||
static void StaticInitialize(void);
|
||||
|
||||
protected:
|
||||
|
@ -78,6 +81,7 @@ private:
|
|||
static boost::mutex m_Mutex;
|
||||
static std::set<Logger::Ptr> m_Loggers;
|
||||
static bool m_ConsoleLogEnabled;
|
||||
static LogSeverity m_ConsoleLogSeverity;
|
||||
|
||||
friend I2_BASE_API void Log(LogSeverity severity, const String& facility,
|
||||
const String& message);
|
||||
|
|
|
@ -37,10 +37,11 @@ String icinga::JsonSerialize(const Value& value)
|
|||
|
||||
char *jsonString;
|
||||
|
||||
if (Application::IsDebugging())
|
||||
jsonString = cJSON_Print(json);
|
||||
else
|
||||
jsonString = cJSON_PrintUnformatted(json);
|
||||
#ifdef _DEBUG
|
||||
jsonString = cJSON_Print(json);
|
||||
#else /* _DEBUG */
|
||||
jsonString = cJSON_PrintUnformatted(json);
|
||||
#endif /* _DEBUG */
|
||||
|
||||
cJSON_Delete(json);
|
||||
|
||||
|
|
Loading…
Reference in New Issue