]> granicus.if.org Git - icinga2/commitdiff
Rename --debug to --log-level.
authorGunnar Beutner <gunnar@beutner.name>
Fri, 23 May 2014 16:05:04 +0000 (18:05 +0200)
committerGunnar Beutner <gunnar@beutner.name>
Fri, 23 May 2014 16:11:21 +0000 (18:11 +0200)
Refs #6276

icinga-app/icinga.cpp
lib/base/application.cpp
lib/base/application.h
lib/base/logger.cpp
lib/base/logger.h
lib/base/serializer.cpp

index 053accab0b66ee2d8638e057710452899581ec84..8f20208245a8acc7423487c8195d5b1d410ea505 100644 (file)
@@ -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")) {
index 8ee0e69a9a3bdea6c53bb7b5037eea6245bc0617..07d781ccd760cb588490a0a38cd1273339ce5455 100644 (file)
@@ -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.
  */
index 90a45e303b01eaa8611538f3f8bbe9989f0d651a..7f3a4ca526040bb7ebbdd3ae37cfbcd409c38f56 100644 (file)
@@ -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);
 
index 14539d874f199a7bce12d419c622a48118d9a350..b92ca31ef731e380075c5cc68411b5f00a9f84a3 100644 (file)
@@ -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;
+}
\ No newline at end of file
index 1a79e74f95168d933fe687eda8dbc3b1ae08ba13..d4bb3ec93872ac38e613e9d6d9b0d1c10fa43852 100644 (file)
@@ -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);
index f868e86d653194ab4c3066b93c3613917ce561c2..c4bd6d466328cce0418a9c57d978872e688595b5 100644 (file)
@@ -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);