]> granicus.if.org Git - icinga2/commitdiff
Add debug log severity for console logger.
authorMichael Friedrich <michael.friedrich@netways.de>
Fri, 23 May 2014 09:56:30 +0000 (11:56 +0200)
committerMichael Friedrich <michael.friedrich@netways.de>
Fri, 23 May 2014 09:57:08 +0000 (11:57 +0200)
Fixes #6276

doc/2-getting-started.md
doc/7-troubleshooting.md
icinga-app/icinga.cpp
lib/base/application.cpp
lib/base/application.h
lib/base/logger.cpp

index 76bf66a3609dca7899248eee130ce04cf1cdcb28..2ef3b96185db22e9ba410ed072acb8f9d055f62b 100644 (file)
@@ -830,7 +830,7 @@ for historical reasons.
       -D [ --define] args   define a constant
       -c [ --config ] arg   parse a configuration file
       -C [ --validate ]     exit after validating the configuration
-      -x [ --debug ]        enable debugging
+      -x [ --debug ] arg    enable debugging with optional severity level specified
       -d [ --daemonize ]    detach from the controlling terminal
       -e [ --errorlog ] arg log fatal errors to the specified log file (only works
                             in combination with --daemonize)
index f4d8c7d5283876db71202dcc32134e920b0842ae..6ce0c0cf26d41b83d293d9b3eeb33d8021464c9e 100644 (file)
@@ -4,12 +4,6 @@ For a more verbose output of the Icinga 2 daemon increase the
 `severity` attribute of the [logs](#logging) to `notice` or
 `debug`.
 
-Additionally you can enable the debug log using
-
-    # icinga2-enable-feature debuglog
-    # service icinga2 restart
-    # tail -f /var/log/icinga2/debug.log
-
 ## <a id="troubleshooting-information-required"></a> Which information is required
 
 * Which distribution and version
@@ -20,6 +14,20 @@ Additionally you can enable the debug log using
 * If the check command failed - what's the output of your manual plugin tests?
 * In case of [debugging](#debug) Icinga 2, the full back traces and outputs
 
+## <a id="troubleshooting-enable-debug-output"></a> Enable Debug Output
+
+Run Icinga 2 in foreground with debugging enabled You can specify the debug
+log severity as additional parameter argument to `-x` (or `--debug`). Default
+is `debug`.
+
+    # /usr/sbin/icinga2 -c /etc/icinga2/icinga2.conf -x notice
+
+Additionally you can enable the debug log using
+
+    # icinga2-enable-feature debuglog
+    # service icinga2 restart
+    # tail -f /var/log/icinga2/debug.log
+
 ## <a id="checks-not-executed"></a> Checks are not executed
 
 * Check the debug log if the check command gets executed
index 3b023fad8c696ec1aa78b3a9ff3fd39bb02f0549..deefb405a373383c2ecde4b77e0ea3bd5b412e4f 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", "enable debugging")
+               ("debug,x", po::value<std::string>(), "enable debugging with optional severity level specified")
                ("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,9 +428,15 @@ int Main(void)
        }
 #endif /* _WIN32 */
 
-       if (g_AppParams.count("debug"))
+       if (g_AppParams.count("debug")) {
                Application::SetDebugging(true);
 
+               String debug_severity = g_AppParams["debug"].as<std::string>();
+
+               if (!debug_severity.IsEmpty())
+                       Application::SetDebuggingSeverity(Logger::StringToSeverity(debug_severity));
+       }
+
        if (g_AppParams.count("help") || g_AppParams.count("version")) {
                String appName = Utility::BaseName(argv[0]);
 
index b393b4d297adf1bd9eaa7076a6457d08382478fc..8ee0e69a9a3bdea6c53bb7b5037eea6245bc0617 100644 (file)
@@ -51,6 +51,7 @@ 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;
@@ -459,6 +460,29 @@ 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 2be7a848f0e980360b2ea230ae581122f335e2b1..90a45e303b01eaa8611538f3f8bbe9989f0d651a 100644 (file)
@@ -24,6 +24,7 @@
 #include "base/application.th"
 #include "base/threadpool.h"
 #include "base/utility.h"
+#include "base/logger_fwd.h"
 
 namespace icinga
 {
@@ -71,6 +72,9 @@ public:
        static void SetDebugging(bool debug);
        static bool IsDebugging(void);
 
+       static void SetDebuggingSeverity(LogSeverity severity);
+       static LogSeverity GetDebuggingSeverity(void);
+
        void UpdatePidFile(const String& filename, pid_t pid = Utility::GetPid());
        void ClosePidFile(bool unlink);
        static pid_t ReadPidFile(const String& filename);
@@ -137,6 +141,7 @@ private:
        static char **m_ArgV; /**< Command-line arguments. */
        FILE *m_PidFile; /**< The PID file */
        static bool m_Debugging; /**< Whether debugging is enabled. */
+       static LogSeverity m_DebuggingSeverity; /**< Whether debugging severity is set. */
        static double m_StartTime;
 
 #ifndef _WIN32
index 86ec150d03295023fd12efc48385fda7a9ffd868..14539d874f199a7bce12d419c622a48118d9a350 100644 (file)
@@ -108,7 +108,7 @@ void icinga::Log(LogSeverity severity, const String& facility,
        LogSeverity defaultLogLevel;
 
        if (Application::IsDebugging())
-               defaultLogLevel = LogDebug;
+               defaultLogLevel = Application::GetDebuggingSeverity();
        else
                defaultLogLevel = LogInformation;