From 16a2d36bdc833fe1132f6e0f58cc5524cfe0fd0d Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Fri, 23 May 2014 18:05:04 +0200 Subject: [PATCH] Rename --debug to --log-level. Refs #6276 --- icinga-app/icinga.cpp | 17 ++++---------- lib/base/application.cpp | 50 ---------------------------------------- lib/base/application.h | 3 --- lib/base/logger.cpp | 19 ++++++++------- lib/base/logger.h | 4 ++++ lib/base/serializer.cpp | 9 ++++---- 6 files changed, 24 insertions(+), 78 deletions(-) diff --git a/icinga-app/icinga.cpp b/icinga-app/icinga.cpp index 053accab0..8f2020824 100644 --- a/icinga-app/icinga.cpp +++ b/icinga-app/icinga.cpp @@ -334,7 +334,7 @@ int Main(void) ("config,c", po::value >(), "parse a configuration file") ("no-config,z", "start without a configuration file") ("validate,C", "exit after validating the configuration") - ("debug,x", po::value(), "enable debugging with severity level specified") + ("log-level,x", po::value(), "specify the log level for the console log") ("errorlog,e", po::value(), "log fatal errors to the specified log file (only works in combination with --daemonize)") #ifndef _WIN32 ("reload-internal", po::value(), "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()); - } 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()); + Logger::SetConsoleLogSeverity(logLevel); } if (g_AppParams.count("help") || g_AppParams.count("version")) { diff --git a/lib/base/application.cpp b/lib/base/application.cpp index 8ee0e69a9..07d781ccd 100644 --- a/lib/base/application.cpp +++ b/lib/base/application.cpp @@ -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. */ diff --git a/lib/base/application.h b/lib/base/application.h index 90a45e303..7f3a4ca52 100644 --- a/lib/base/application.h +++ b/lib/base/application.h @@ -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); diff --git a/lib/base/logger.cpp b/lib/base/logger.cpp index 14539d874..b92ca31ef 100644 --- a/lib/base/logger.cpp +++ b/lib/base/logger.cpp @@ -36,6 +36,7 @@ INITIALIZE_ONCE(&Logger::StaticInitialize); std::set 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; +} \ No newline at end of file diff --git a/lib/base/logger.h b/lib/base/logger.h index 1a79e74f9..d4bb3ec93 100644 --- a/lib/base/logger.h +++ b/lib/base/logger.h @@ -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 m_Loggers; static bool m_ConsoleLogEnabled; + static LogSeverity m_ConsoleLogSeverity; friend I2_BASE_API void Log(LogSeverity severity, const String& facility, const String& message); diff --git a/lib/base/serializer.cpp b/lib/base/serializer.cpp index f868e86d6..c4bd6d466 100644 --- a/lib/base/serializer.cpp +++ b/lib/base/serializer.cpp @@ -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);