path = "/var/log/icinga2/debug.log"
}
-If you're starting Icinga 2 not as daemon, but in foreground
-using `/usr/sbin/icinga2 -c /etc/icinga2/icinga2.conf` you may
-want to enable console logging temporary too.
-
- object ConsoleLogger "debug-console" {
- severity = "debug"
- }
-
-
-
duration |**Optional.** How long the downtime lasts. Only has an effect for flexible (non-fixed) downtimes.
ranges |**Required.** A dictionary containing information which days and durations apply to this timeperiod.
-### <a id="objecttype-consolelogger"></a> ConsoleLogger
-
-Specifies Icinga 2 logging to the console.
-
-Example:
-
- object ConsoleLogger "my-debug-console" {
- severity = "debug"
- }
-
-Attributes:
-
- Name |Description
- ----------------|----------------
- severity |**Optional.** The minimum severity for this log. Can be "debug", "information", "warning" or "critical". Defaults to "information".
-
### <a id="objecttype-filelogger"></a> FileLogger
Specifies Icinga 2 logging to a file.
#include "config/configcompiler.h"
#include "config/configitembuilder.h"
#include "base/application.h"
-#include "base/logger_fwd.h"
+#include "base/logger.h"
#include "base/timer.h"
#include "base/utility.h"
#include "base/exception.h"
errorLog = g_AppParams["errorlog"].as<String>();
Daemonize(errorLog);
+ Logger::DisableConsoleLog();
}
bool validateOnly = g_AppParams.count("validate");
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
mkclass_target(application.ti application.th)
-mkclass_target(consolelogger.ti consolelogger.th)
mkclass_target(dynamicobject.ti dynamicobject.th)
mkclass_target(filelogger.ti filelogger.th)
mkclass_target(logger.ti logger.th)
mkclass_target(sysloglogger.ti sysloglogger.th)
add_library(base SHARED
- application.cpp application.th array.cpp bufferedstream.cpp consolelogger.cpp
- consolelogger.th context.cpp convert.cpp dictionary.cpp dynamicobject.cpp
- dynamicobject.th dynamictype.cpp exception.cpp fifo.cpp filelogger.cpp
- filelogger.th logger.cpp logger.th netstring.cpp networkstream.cpp object.cpp
- objectlock.cpp process.cpp process-unix.cpp process-windows.cpp qstring.cpp
- ringbuffer.cpp script.cpp script.th scriptfunction.cpp scriptfunctionwrapper.cpp
- scriptinterpreter.cpp scriptlanguage.cpp scriptvariable.cpp serializer.cpp
- socket.cpp stacktrace.cpp stdiostream.cpp stream_bio.cpp stream.cpp
- streamlogger.cpp streamlogger.th sysloglogger.cpp sysloglogger.th tcpsocket.cpp
- threadpool.cpp timer.cpp tlsstream.cpp tlsutility.cpp type.cpp unixsocket.cpp
- utility.cpp value.cpp workqueue.cpp zlibstream.cpp
+ application.cpp application.th array.cpp bufferedstream.cpp context.cpp
+ convert.cpp dictionary.cpp dynamicobject.cpp dynamicobject.th dynamictype.cpp
+ exception.cpp fifo.cpp filelogger.cpp filelogger.th logger.cpp logger.th
+ netstring.cpp networkstream.cpp object.cpp objectlock.cpp process.cpp
+ process-unix.cpp process-windows.cpp qstring.cpp ringbuffer.cpp script.cpp
+ script.th scriptfunction.cpp scriptfunctionwrapper.cpp scriptinterpreter.cpp
+ scriptlanguage.cpp scriptvariable.cpp serializer.cpp socket.cpp stacktrace.cpp
+ stdiostream.cpp stream_bio.cpp stream.cpp streamlogger.cpp streamlogger.th
+ sysloglogger.cpp sysloglogger.th tcpsocket.cpp threadpool.cpp timer.cpp
+ tlsstream.cpp tlsutility.cpp type.cpp unixsocket.cpp utility.cpp value.cpp
+ workqueue.cpp zlibstream.cpp
)
target_link_libraries(base ${CMAKE_DL_LIBS} ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES} cJSON mmatch)
+++ /dev/null
-/******************************************************************************
- * Icinga 2 *
- * Copyright (C) 2012-2013 Icinga Development Team (http://www.icinga.org/) *
- * *
- * This program is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU General Public License *
- * as published by the Free Software Foundation; either version 2 *
- * of the License, or (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the Free Software Foundation *
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
- ******************************************************************************/
-
-#include "base/consolelogger.h"
-#include "base/dynamictype.h"
-#include <iostream>
-
-using namespace icinga;
-
-REGISTER_TYPE(ConsoleLogger);
-
-/**
- * Constructor for the ConsoleLogger class.
- */
-void ConsoleLogger::Start()
-{
- StreamLogger::Start();
-
- BindStream(&std::cout, false);
-}
+++ /dev/null
-/******************************************************************************
- * Icinga 2 *
- * Copyright (C) 2012-2013 Icinga Development Team (http://www.icinga.org/) *
- * *
- * This program is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU General Public License *
- * as published by the Free Software Foundation; either version 2 *
- * of the License, or (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the Free Software Foundation *
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
- ******************************************************************************/
-
-#ifndef CONSOLELOGGER_H
-#define CONSOLELOGGER_H
-
-#include "base/i2-base.h"
-#include "base/consolelogger.th"
-
-namespace icinga
-{
-
-/**
- * A logger that logs to the console.
- *
- * @ingroup base
- */
-class I2_BASE_API ConsoleLogger : public ObjectImpl<ConsoleLogger>
-{
-public:
- DECLARE_PTR_TYPEDEFS(ConsoleLogger);
-
- virtual void Start(void);
-};
-
-}
-
-#endif /* CONSOLELOGGER_H */
+++ /dev/null
-#include "base/streamlogger.h"
-
-namespace icinga
-{
-
-class ConsoleLogger : StreamLogger
-{
-};
-
-}
\ No newline at end of file
std::set<Logger::Ptr> Logger::m_Loggers;
boost::mutex Logger::m_Mutex;
+bool Logger::m_ConsoleLogEnabled = true;
/**
* Constructor for the Logger class.
}
}
- bool processed = false;
-
BOOST_FOREACH(const Logger::Ptr& logger, Logger::GetLoggers()) {
- {
- ObjectLock llock(logger);
-
- if (!logger->IsActive())
- continue;
+ ObjectLock llock(logger);
- if (entry.Severity >= logger->GetMinSeverity())
- logger->ProcessLogEntry(entry);
- }
+ if (!logger->IsActive())
+ continue;
- processed = true;
+ if (entry.Severity >= logger->GetMinSeverity())
+ logger->ProcessLogEntry(entry);
}
LogSeverity defaultLogLevel;
else
defaultLogLevel = LogInformation;
- if (!processed && entry.Severity >= defaultLogLevel) {
+ if (Logger::IsConsoleLogEnabled() && entry.Severity >= defaultLogLevel) {
static bool tty = StreamLogger::IsTty(std::cout);
StreamLogger::ProcessLogEntry(std::cout, tty, entry);
else
BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid severity: " + severity));
}
+
+void Logger::DisableConsoleLog(void)
+{
+ m_ConsoleLogEnabled = false;
+}
+
+bool Logger::IsConsoleLogEnabled(void)
+{
+ return m_ConsoleLogEnabled;
+}
+
static std::set<Logger::Ptr> GetLoggers(void);
+ static void DisableConsoleLog(void);
+ static bool IsConsoleLogEnabled(void);
+
protected:
virtual void Start(void);
virtual void Stop(void);
private:
static boost::mutex m_Mutex;
static std::set<Logger::Ptr> m_Loggers;
+ static bool m_ConsoleLogEnabled;
friend void Log(LogSeverity severity, const String& facility,
const String& message);
%attribute string "severity"
}
-type ConsoleLogger inherits Logger {
-}
-
type FileLogger inherits Logger {
%require "path",
%attribute string "path"