1 /******************************************************************************
3 * Copyright (C) 2012-2016 Icinga Development Team (https://www.icinga.org/) *
5 * This program is free software; you can redistribute it and/or *
6 * modify it under the terms of the GNU General Public License *
7 * as published by the Free Software Foundation; either version 2 *
8 * of the License, or (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the Free Software Foundation *
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ******************************************************************************/
23 #include "base/i2-base.hpp"
24 #include "base/logger.thpp"
51 double Timestamp; /**< The timestamp when this log entry was created. */
52 LogSeverity Severity; /**< The severity of this log entry. */
53 String Facility; /**< The facility this log entry belongs to. */
54 String Message; /**< The log entry's message. */
62 class I2_BASE_API Logger : public ObjectImpl<Logger>
65 DECLARE_OBJECT(Logger);
67 static String SeverityToString(LogSeverity severity);
68 static LogSeverity StringToSeverity(const String& severity);
70 LogSeverity GetMinSeverity(void) const;
73 * Processes the log entry and writes it to the log that is
74 * represented by this ILogger object.
76 * @param entry The log entry that is to be processed.
78 virtual void ProcessLogEntry(const LogEntry& entry) = 0;
80 virtual void Flush(void) = 0;
82 static std::set<Logger::Ptr> GetLoggers(void);
84 static void DisableConsoleLog(void);
85 static void EnableConsoleLog(void);
86 static bool IsConsoleLogEnabled(void);
87 static void DisableTimestamp(bool);
88 static bool IsTimestampEnabled(void);
90 static void SetConsoleLogSeverity(LogSeverity logSeverity);
91 static LogSeverity GetConsoleLogSeverity(void);
93 static void StaticInitialize(void);
96 virtual void Start(bool runtimeCreated) override;
97 virtual void Stop(bool runtimeRemoved) override;
100 static boost::mutex m_Mutex;
101 static std::set<Logger::Ptr> m_Loggers;
102 static bool m_ConsoleLogEnabled;
103 static bool m_TimestampEnabled;
104 static LogSeverity m_ConsoleLogSeverity;
107 I2_BASE_API void IcingaLog(LogSeverity severity, const String& facility, const String& message);
112 inline Log(LogSeverity severity, const String& facility, const String& message)
113 : m_Severity(severity), m_Facility(facility)
118 inline Log(LogSeverity severity, const String& facility)
119 : m_Severity(severity), m_Facility(facility)
124 IcingaLog(m_Severity, m_Facility, m_Buffer.str());
128 Log& operator<<(const T& val)
135 LogSeverity m_Severity;
137 std::ostringstream m_Buffer;
140 Log(const Log& other);
141 Log& operator=(const Log& rhs);
146 #endif /* LOGGER_H */