1 /******************************************************************************
3 * Copyright (C) 2012-2018 Icinga Development Team (https://www.icinga.com/) *
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-ti.hpp"
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 Logger : public ObjectImpl<Logger>
65 DECLARE_OBJECT(Logger);
67 static String SeverityToString(LogSeverity severity);
68 static LogSeverity StringToSeverity(const String& severity);
70 LogSeverity GetMinSeverity() 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() = 0;
82 static std::set<Logger::Ptr> GetLoggers();
84 static void DisableConsoleLog();
85 static void EnableConsoleLog();
86 static bool IsConsoleLogEnabled();
87 static void DisableTimestamp(bool);
88 static bool IsTimestampEnabled();
90 static void SetConsoleLogSeverity(LogSeverity logSeverity);
91 static LogSeverity GetConsoleLogSeverity();
93 void ValidateSeverity(const Lazy<String>& lvalue, const ValidationUtils& utils) final;
96 void Start(bool runtimeCreated) override;
97 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;
111 Log(const Log& other) = delete;
112 Log& operator=(const Log& rhs) = delete;
114 Log(LogSeverity severity, String facility, const String& message);
115 Log(LogSeverity severity, String facility);
120 Log& operator<<(const T& val)
126 Log& operator<<(const char *val);
129 LogSeverity m_Severity;
131 std::ostringstream m_Buffer;
134 extern template Log& Log::operator<<(const Value&);
135 extern template Log& Log::operator<<(const String&);
136 extern template Log& Log::operator<<(const std::string&);
137 extern template Log& Log::operator<<(const bool&);
138 extern template Log& Log::operator<<(const unsigned int&);
139 extern template Log& Log::operator<<(const int&);
140 extern template Log& Log::operator<<(const unsigned long&);
141 extern template Log& Log::operator<<(const long&);
142 extern template Log& Log::operator<<(const double&);
146 #endif /* LOGGER_H */