Remove the ConsoleLogger class and keep the default console log enabled until we daemonize.

Refs #5342
This commit is contained in:
Gunnar Beutner 2013-12-16 17:05:23 +01:00
parent 07e4bc03bc
commit 162cee5c40
10 changed files with 35 additions and 144 deletions

View File

@ -25,13 +25,3 @@ and forward the `debug` serverity into an Icinga 2 debug file.
path = "/var/log/icinga2/debug.log" 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"
}

View File

@ -350,22 +350,6 @@ Attributes:
duration |**Optional.** How long the downtime lasts. Only has an effect for flexible (non-fixed) downtimes. 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. 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 ### <a id="objecttype-filelogger"></a> FileLogger
Specifies Icinga 2 logging to a file. Specifies Icinga 2 logging to a file.

View File

@ -21,7 +21,7 @@
#include "config/configcompiler.h" #include "config/configcompiler.h"
#include "config/configitembuilder.h" #include "config/configitembuilder.h"
#include "base/application.h" #include "base/application.h"
#include "base/logger_fwd.h" #include "base/logger.h"
#include "base/timer.h" #include "base/timer.h"
#include "base/utility.h" #include "base/utility.h"
#include "base/exception.h" #include "base/exception.h"
@ -370,6 +370,7 @@ int main(int argc, char **argv)
errorLog = g_AppParams["errorlog"].as<String>(); errorLog = g_AppParams["errorlog"].as<String>();
Daemonize(errorLog); Daemonize(errorLog);
Logger::DisableConsoleLog();
} }
bool validateOnly = g_AppParams.count("validate"); bool validateOnly = g_AppParams.count("validate");

View File

@ -16,7 +16,6 @@
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
mkclass_target(application.ti application.th) mkclass_target(application.ti application.th)
mkclass_target(consolelogger.ti consolelogger.th)
mkclass_target(dynamicobject.ti dynamicobject.th) mkclass_target(dynamicobject.ti dynamicobject.th)
mkclass_target(filelogger.ti filelogger.th) mkclass_target(filelogger.ti filelogger.th)
mkclass_target(logger.ti logger.th) mkclass_target(logger.ti logger.th)
@ -25,17 +24,17 @@ mkclass_target(streamlogger.ti streamlogger.th)
mkclass_target(sysloglogger.ti sysloglogger.th) mkclass_target(sysloglogger.ti sysloglogger.th)
add_library(base SHARED add_library(base SHARED
application.cpp application.th array.cpp bufferedstream.cpp consolelogger.cpp application.cpp application.th array.cpp bufferedstream.cpp context.cpp
consolelogger.th context.cpp convert.cpp dictionary.cpp dynamicobject.cpp convert.cpp dictionary.cpp dynamicobject.cpp dynamicobject.th dynamictype.cpp
dynamicobject.th dynamictype.cpp exception.cpp fifo.cpp filelogger.cpp exception.cpp fifo.cpp filelogger.cpp filelogger.th logger.cpp logger.th
filelogger.th logger.cpp logger.th netstring.cpp networkstream.cpp object.cpp netstring.cpp networkstream.cpp object.cpp objectlock.cpp process.cpp
objectlock.cpp process.cpp process-unix.cpp process-windows.cpp qstring.cpp process-unix.cpp process-windows.cpp qstring.cpp ringbuffer.cpp script.cpp
ringbuffer.cpp script.cpp script.th scriptfunction.cpp scriptfunctionwrapper.cpp script.th scriptfunction.cpp scriptfunctionwrapper.cpp scriptinterpreter.cpp
scriptinterpreter.cpp scriptlanguage.cpp scriptvariable.cpp serializer.cpp scriptlanguage.cpp scriptvariable.cpp serializer.cpp socket.cpp stacktrace.cpp
socket.cpp stacktrace.cpp stdiostream.cpp stream_bio.cpp stream.cpp stdiostream.cpp stream_bio.cpp stream.cpp streamlogger.cpp streamlogger.th
streamlogger.cpp streamlogger.th sysloglogger.cpp sysloglogger.th tcpsocket.cpp sysloglogger.cpp sysloglogger.th tcpsocket.cpp threadpool.cpp timer.cpp
threadpool.cpp timer.cpp tlsstream.cpp tlsutility.cpp type.cpp unixsocket.cpp tlsstream.cpp tlsutility.cpp type.cpp unixsocket.cpp utility.cpp value.cpp
utility.cpp value.cpp workqueue.cpp zlibstream.cpp workqueue.cpp zlibstream.cpp
) )
target_link_libraries(base ${CMAKE_DL_LIBS} ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES} cJSON mmatch) target_link_libraries(base ${CMAKE_DL_LIBS} ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES} cJSON mmatch)

View File

@ -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 <iostream>
using namespace icinga;
REGISTER_TYPE(ConsoleLogger);
/**
* Constructor for the ConsoleLogger class.
*/
void ConsoleLogger::Start()
{
StreamLogger::Start();
BindStream(&std::cout, false);
}

View File

@ -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<ConsoleLogger>
{
public:
DECLARE_PTR_TYPEDEFS(ConsoleLogger);
virtual void Start(void);
};
}
#endif /* CONSOLELOGGER_H */

View File

@ -1,10 +0,0 @@
#include "base/streamlogger.h"
namespace icinga
{
class ConsoleLogger : StreamLogger
{
};
}

View File

@ -35,6 +35,7 @@ REGISTER_TYPE(Logger);
std::set<Logger::Ptr> Logger::m_Loggers; std::set<Logger::Ptr> Logger::m_Loggers;
boost::mutex Logger::m_Mutex; boost::mutex Logger::m_Mutex;
bool Logger::m_ConsoleLogEnabled = true;
/** /**
* Constructor for the Logger class. * 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()) { BOOST_FOREACH(const Logger::Ptr& logger, Logger::GetLoggers()) {
{ ObjectLock llock(logger);
ObjectLock llock(logger);
if (!logger->IsActive()) if (!logger->IsActive())
continue; continue;
if (entry.Severity >= logger->GetMinSeverity()) if (entry.Severity >= logger->GetMinSeverity())
logger->ProcessLogEntry(entry); logger->ProcessLogEntry(entry);
}
processed = true;
} }
LogSeverity defaultLogLevel; LogSeverity defaultLogLevel;
@ -108,7 +103,7 @@ void icinga::Log(LogSeverity severity, const String& facility,
else else
defaultLogLevel = LogInformation; defaultLogLevel = LogInformation;
if (!processed && entry.Severity >= defaultLogLevel) { if (Logger::IsConsoleLogEnabled() && entry.Severity >= defaultLogLevel) {
static bool tty = StreamLogger::IsTty(std::cout); static bool tty = StreamLogger::IsTty(std::cout);
StreamLogger::ProcessLogEntry(std::cout, tty, entry); StreamLogger::ProcessLogEntry(std::cout, tty, entry);
@ -168,3 +163,14 @@ LogSeverity Logger::StringToSeverity(const String& severity)
else else
BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid severity: " + severity)); BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid severity: " + severity));
} }
void Logger::DisableConsoleLog(void)
{
m_ConsoleLogEnabled = false;
}
bool Logger::IsConsoleLogEnabled(void)
{
return m_ConsoleLogEnabled;
}

View File

@ -66,6 +66,9 @@ public:
static std::set<Logger::Ptr> GetLoggers(void); static std::set<Logger::Ptr> GetLoggers(void);
static void DisableConsoleLog(void);
static bool IsConsoleLogEnabled(void);
protected: protected:
virtual void Start(void); virtual void Start(void);
virtual void Stop(void); virtual void Stop(void);
@ -73,6 +76,7 @@ protected:
private: private:
static boost::mutex m_Mutex; static boost::mutex m_Mutex;
static std::set<Logger::Ptr> m_Loggers; static std::set<Logger::Ptr> m_Loggers;
static bool m_ConsoleLogEnabled;
friend void Log(LogSeverity severity, const String& facility, friend void Log(LogSeverity severity, const String& facility,
const String& message); const String& message);

View File

@ -43,9 +43,6 @@ type Logger {
%attribute string "severity" %attribute string "severity"
} }
type ConsoleLogger inherits Logger {
}
type FileLogger inherits Logger { type FileLogger inherits Logger {
%require "path", %require "path",
%attribute string "path" %attribute string "path"