diff --git a/doc/2-getting-started.md b/doc/2-getting-started.md
index 76bf66a36..2ef3b9618 100644
--- a/doc/2-getting-started.md
+++ b/doc/2-getting-started.md
@@ -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)
diff --git a/doc/7-troubleshooting.md b/doc/7-troubleshooting.md
index f4d8c7d52..6ce0c0cf2 100644
--- a/doc/7-troubleshooting.md
+++ b/doc/7-troubleshooting.md
@@ -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
-
## 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
+## 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
+
## Checks are not executed
* Check the debug log if the check command gets executed
diff --git a/icinga-app/icinga.cpp b/icinga-app/icinga.cpp
index 3b023fad8..deefb405a 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", "enable debugging")
+ ("debug,x", po::value(), "enable debugging with optional severity level specified")
("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,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();
+
+ 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]);
diff --git a/lib/base/application.cpp b/lib/base/application.cpp
index b393b4d29..8ee0e69a9 100644
--- a/lib/base/application.cpp
+++ b/lib/base/application.cpp
@@ -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.
*/
diff --git a/lib/base/application.h b/lib/base/application.h
index 2be7a848f..90a45e303 100644
--- a/lib/base/application.h
+++ b/lib/base/application.h
@@ -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
diff --git a/lib/base/logger.cpp b/lib/base/logger.cpp
index 86ec150d0..14539d874 100644
--- a/lib/base/logger.cpp
+++ b/lib/base/logger.cpp
@@ -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;