Elements 6.1.2
A C++ base framework for the Euclid Software.
Loading...
Searching...
No Matches
Logging.h
Go to the documentation of this file.
1
26#ifndef ELEMENTSKERNEL_ELEMENTSKERNEL_LOGGING_H_
27#define ELEMENTSKERNEL_ELEMENTSKERNEL_LOGGING_H_
28
29#include <map>
30#include <string>
31#include <utility> // for forward
32
33#include <log4cpp/Category.hh>
34
35#include "ElementsKernel/Export.h" // ELEMENTS_API
36#include "ElementsKernel/Path.h" // for Item
37
38namespace Elements {
39
94
95private:
96 // We declare the LogMessageStream here because it is used from the public
97 // functions. It is defined in the private section at the end.
98 class LogMessageStream;
99
100public:
107 static Logging getLogger(const std::string& name = "");
108
119 static void setLevel(std::string level);
120
137 static void setLogFile(const Path::Item& fileName);
138
143 void debug(const std::string& logMessage) {
144 m_log4cppLogger.debug(logMessage);
145 }
146
152 template <typename... Args>
153 void debug(const char* stringFormat, Args&&... args) {
154 m_log4cppLogger.debug(stringFormat, std::forward<Args>(args)...);
155 }
156
163 return LogMessageStream{m_log4cppLogger, &log4cpp::Category::debug};
164 }
165
170 void info(const std::string& logMessage) {
171 m_log4cppLogger.info(logMessage);
172 }
173
179 template <typename... Args>
180 void info(const char* stringFormat, Args&&... args) {
181 m_log4cppLogger.info(stringFormat, std::forward<Args>(args)...);
182 }
183
190 return LogMessageStream{m_log4cppLogger, &log4cpp::Category::info};
191 }
192
197 void warn(const std::string& logMessage) {
198 m_log4cppLogger.warn(logMessage);
199 }
200
206 template <typename... Args>
207 void warn(const char* stringFormat, Args&&... args) {
208 m_log4cppLogger.warn(stringFormat, std::forward<Args>(args)...);
209 }
210
217 return LogMessageStream{m_log4cppLogger, &log4cpp::Category::warn};
218 }
219
224 void error(const std::string& logMessage) {
225 m_log4cppLogger.error(logMessage);
226 }
227
233 template <typename... Args>
234 void error(const char* stringFormat, Args&&... args) {
235 m_log4cppLogger.error(stringFormat, std::forward<Args>(args)...);
236 }
237
244 return LogMessageStream{m_log4cppLogger, &log4cpp::Category::error};
245 }
246
251 void fatal(const std::string& logMessage) {
252 m_log4cppLogger.fatal(logMessage);
253 }
254
260 template <typename... Args>
261 void fatal(const char* stringFormat, Args&&... args) {
262 m_log4cppLogger.fatal(stringFormat, std::forward<Args>(args)...);
263 }
264
271 return LogMessageStream{m_log4cppLogger, &log4cpp::Category::fatal};
272 }
273
279 void log(log4cpp::Priority::Value level, const std::string& logMessage) {
280 m_log4cppLogger.log(level, logMessage);
281 }
282
289 template <typename... Args>
290 void log(log4cpp::Priority::Value level, const char* stringFormat, Args&&... args) {
291 m_log4cppLogger.log(level, stringFormat, std::forward<Args>(args)...);
292 }
293
294private:
295 explicit Logging(log4cpp::Category& log4cppLogger);
296
297 log4cpp::Category& m_log4cppLogger;
298
310 // The P_log_func is a pointer to member function. If you have no idea what
311 // this is don't get scared! Just have a look in the following link:
312 // http://www.codeproject.com/Articles/7150/Member-Function-Pointers-and-the-Fastest-Possible
313 using P_log_func = void (log4cpp::Category::*)(const std::string&);
314
315 public:
316 LogMessageStream(log4cpp::Category& logger, P_log_func log_func);
320 template <typename T>
322 m_message << m;
323 return *this;
324 }
325
326 private:
327 log4cpp::Category& m_logger;
329 std::stringstream m_message{};
330 };
331};
332
333} // namespace Elements
334
335#endif // ELEMENTSKERNEL_ELEMENTSKERNEL_LOGGING_H_
336
defines the macros to be used for explicit export of the symbols
provide functions to retrieve resources pointed by environment variables
A helper class for logging messages using the "<<" operator.
Definition: Logging.h:309
LogMessageStream(log4cpp::Category &logger, P_log_func log_func)
LogMessageStream & operator<<(const T &m)
Definition: Logging.h:321
void(log4cpp::Category::*)(const std::string &) P_log_func
Definition: Logging.h:313
log4cpp::Category & m_logger
Definition: Logging.h:327
Logging API of the Elements framework.
Definition: Logging.h:93
void error(const std::string &logMessage)
Definition: Logging.h:224
void debug(const std::string &logMessage)
Definition: Logging.h:143
void log(log4cpp::Priority::Value level, const char *stringFormat, Args &&... args)
Definition: Logging.h:290
void warn(const std::string &logMessage)
Definition: Logging.h:197
LogMessageStream error()
Definition: Logging.h:243
LogMessageStream warn()
Definition: Logging.h:216
log4cpp::Category & m_log4cppLogger
Definition: Logging.h:297
void log(log4cpp::Priority::Value level, const std::string &logMessage)
Definition: Logging.h:279
void fatal(const char *stringFormat, Args &&... args)
Definition: Logging.h:261
LogMessageStream fatal()
Definition: Logging.h:270
void warn(const char *stringFormat, Args &&... args)
Definition: Logging.h:207
void debug(const char *stringFormat, Args &&... args)
Definition: Logging.h:153
LogMessageStream info()
Definition: Logging.h:189
void fatal(const std::string &logMessage)
Definition: Logging.h:251
void error(const char *stringFormat, Args &&... args)
Definition: Logging.h:234
void info(const std::string &logMessage)
Definition: Logging.h:170
void info(const char *stringFormat, Args &&... args)
Definition: Logging.h:180
LogMessageStream debug()
Definition: Logging.h:162
#define ELEMENTS_API
Dummy definitions for the backward compatibility mode.
Definition: Export.h:74