From 162cee5c40e9c6127fc6ef99ad4499d1f6d77503 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Mon, 16 Dec 2013 17:05:23 +0100 Subject: [PATCH] Remove the ConsoleLogger class and keep the default console log enabled until we daemonize. Refs #5342 --- doc/3.10-logging.md | 10 --------- doc/4.3-object-types.md | 16 -------------- icinga-app/icinga.cpp | 3 ++- lib/base/CMakeLists.txt | 23 ++++++++++---------- lib/base/consolelogger.cpp | 36 ------------------------------- lib/base/consolelogger.h | 44 -------------------------------------- lib/base/consolelogger.ti | 10 --------- lib/base/logger.cpp | 30 +++++++++++++++----------- lib/base/logger.h | 4 ++++ lib/config/base-type.conf | 3 --- 10 files changed, 35 insertions(+), 144 deletions(-) delete mode 100644 lib/base/consolelogger.cpp delete mode 100644 lib/base/consolelogger.h delete mode 100644 lib/base/consolelogger.ti diff --git a/doc/3.10-logging.md b/doc/3.10-logging.md index 973279888..051f671ea 100644 --- a/doc/3.10-logging.md +++ b/doc/3.10-logging.md @@ -25,13 +25,3 @@ and forward the `debug` serverity into an Icinga 2 debug file. 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" - } - - - diff --git a/doc/4.3-object-types.md b/doc/4.3-object-types.md index e9ddef1c0..5edce0b09 100644 --- a/doc/4.3-object-types.md +++ b/doc/4.3-object-types.md @@ -350,22 +350,6 @@ Attributes: 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. -### 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". - ### FileLogger Specifies Icinga 2 logging to a file. diff --git a/icinga-app/icinga.cpp b/icinga-app/icinga.cpp index 01313ead6..5995dc1b6 100644 --- a/icinga-app/icinga.cpp +++ b/icinga-app/icinga.cpp @@ -21,7 +21,7 @@ #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" @@ -370,6 +370,7 @@ int main(int argc, char **argv) errorLog = g_AppParams["errorlog"].as(); Daemonize(errorLog); + Logger::DisableConsoleLog(); } bool validateOnly = g_AppParams.count("validate"); diff --git a/lib/base/CMakeLists.txt b/lib/base/CMakeLists.txt index ac59e58d0..e9f027abc 100644 --- a/lib/base/CMakeLists.txt +++ b/lib/base/CMakeLists.txt @@ -16,7 +16,6 @@ # 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) @@ -25,17 +24,17 @@ mkclass_target(streamlogger.ti streamlogger.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) diff --git a/lib/base/consolelogger.cpp b/lib/base/consolelogger.cpp deleted file mode 100644 index 3a47b3af2..000000000 --- a/lib/base/consolelogger.cpp +++ /dev/null @@ -1,36 +0,0 @@ -/****************************************************************************** - * 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 - -using namespace icinga; - -REGISTER_TYPE(ConsoleLogger); - -/** - * Constructor for the ConsoleLogger class. - */ -void ConsoleLogger::Start() -{ - StreamLogger::Start(); - - BindStream(&std::cout, false); -} diff --git a/lib/base/consolelogger.h b/lib/base/consolelogger.h deleted file mode 100644 index 8e8306dca..000000000 --- a/lib/base/consolelogger.h +++ /dev/null @@ -1,44 +0,0 @@ -/****************************************************************************** - * 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 -{ -public: - DECLARE_PTR_TYPEDEFS(ConsoleLogger); - - virtual void Start(void); -}; - -} - -#endif /* CONSOLELOGGER_H */ diff --git a/lib/base/consolelogger.ti b/lib/base/consolelogger.ti deleted file mode 100644 index 4059f4551..000000000 --- a/lib/base/consolelogger.ti +++ /dev/null @@ -1,10 +0,0 @@ -#include "base/streamlogger.h" - -namespace icinga -{ - -class ConsoleLogger : StreamLogger -{ -}; - -} \ No newline at end of file diff --git a/lib/base/logger.cpp b/lib/base/logger.cpp index c3ce6e24d..a703944ad 100644 --- a/lib/base/logger.cpp +++ b/lib/base/logger.cpp @@ -35,6 +35,7 @@ REGISTER_TYPE(Logger); std::set Logger::m_Loggers; boost::mutex Logger::m_Mutex; +bool Logger::m_ConsoleLogEnabled = true; /** * Constructor for the Logger class. @@ -85,20 +86,14 @@ void icinga::Log(LogSeverity severity, const String& facility, } } - 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; @@ -108,7 +103,7 @@ void icinga::Log(LogSeverity severity, const String& facility, 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); @@ -168,3 +163,14 @@ LogSeverity Logger::StringToSeverity(const String& severity) else BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid severity: " + severity)); } + +void Logger::DisableConsoleLog(void) +{ + m_ConsoleLogEnabled = false; +} + +bool Logger::IsConsoleLogEnabled(void) +{ + return m_ConsoleLogEnabled; +} + diff --git a/lib/base/logger.h b/lib/base/logger.h index ca656ffd4..854c14d66 100644 --- a/lib/base/logger.h +++ b/lib/base/logger.h @@ -66,6 +66,9 @@ public: static std::set GetLoggers(void); + static void DisableConsoleLog(void); + static bool IsConsoleLogEnabled(void); + protected: virtual void Start(void); virtual void Stop(void); @@ -73,6 +76,7 @@ protected: private: static boost::mutex m_Mutex; static std::set m_Loggers; + static bool m_ConsoleLogEnabled; friend void Log(LogSeverity severity, const String& facility, const String& message); diff --git a/lib/config/base-type.conf b/lib/config/base-type.conf index fb6001bc9..063843e57 100644 --- a/lib/config/base-type.conf +++ b/lib/config/base-type.conf @@ -43,9 +43,6 @@ type Logger { %attribute string "severity" } -type ConsoleLogger inherits Logger { -} - type FileLogger inherits Logger { %require "path", %attribute string "path" -- 2.40.0