[73] | 1 | // %pacpus:license{
|
---|
| 2 | // This file is part of the PACPUS framework distributed under the
|
---|
| 3 | // CECILL-C License, Version 1.0.
|
---|
| 4 | // %pacpus:license}
|
---|
| 5 | /// @file
|
---|
| 6 | /// @author Marek Kurdej <firstname.surname@utc.fr>
|
---|
| 7 | /// @date March, 2012
|
---|
| 8 | /// @version $Id: Log.h 116 2013-06-25 11:44:25Z kurdejma $
|
---|
| 9 | /// @copyright Copyright (c) UTC/CNRS Heudiasyc 2006 - 2013. All rights reserved.
|
---|
| 10 | /// @brief Logging facility.
|
---|
| 11 | ///
|
---|
| 12 | /// Detailed description.
|
---|
| 13 |
|
---|
| 14 | #ifndef DEF_PACPUS_LOG_H
|
---|
| 15 | #define DEF_PACPUS_LOG_H
|
---|
| 16 |
|
---|
[116] | 17 | #include <Pacpus/kernel/PacpusLibConfig.h>
|
---|
[73] | 18 |
|
---|
| 19 | namespace pacpus {
|
---|
| 20 |
|
---|
| 21 | /// Static log facility initializer
|
---|
| 22 | ///
|
---|
| 23 | /// Uses Schwarz counter (nifty counter) idiom to initialize the log before
|
---|
| 24 | /// other static objects that could use the log.
|
---|
| 25 | static class PACPUSLIB_API LogConfigurator
|
---|
| 26 | {
|
---|
| 27 | public:
|
---|
| 28 | LogConfigurator();
|
---|
| 29 | ~LogConfigurator();
|
---|
| 30 |
|
---|
| 31 | static void configureLoggerWithFile(const char * configFilename);
|
---|
| 32 | } initializer; // using Schwarz/nifty counter idiom for static initialization
|
---|
| 33 |
|
---|
| 34 | } // namespace pacpus
|
---|
| 35 |
|
---|
| 36 | #ifdef PACPUS_USE_LOG
|
---|
| 37 | #include <log4cxx/logger.h>
|
---|
| 38 |
|
---|
| 39 | class QString;
|
---|
| 40 |
|
---|
| 41 | #define DECLARE_STATIC_LOGGER(name) \
|
---|
| 42 | static log4cxx::LoggerPtr logger(log4cxx::Logger::getLogger(name))
|
---|
| 43 |
|
---|
[116] | 44 | // https://devel.hds.utc.fr/projects/pacpus/ticket/55
|
---|
[112] | 45 | #define LOG_TRACE(message) do{LOG4CXX_TRACE(logger, message);} while(false)
|
---|
| 46 | #define LOG_DEBUG(message) do{LOG4CXX_DEBUG(logger, message);} while(false)
|
---|
| 47 | #define LOG_INFO(message) do{LOG4CXX_INFO(logger, message);} while(false)
|
---|
| 48 | #define LOG_WARN(message) do{LOG4CXX_WARN(logger, message);} while(false)
|
---|
| 49 | #define LOG_ERROR(message) do{LOG4CXX_ERROR(logger, message);} while(false)
|
---|
| 50 | #define LOG_FATAL(message) do{LOG4CXX_FATAL(logger, message);} while(false)
|
---|
[73] | 51 |
|
---|
| 52 | /// Output stream ::log4cxx::helpers::CharMessageBuffer operator for QString
|
---|
| 53 | PACPUSLIB_API ::log4cxx::helpers::CharMessageBuffer & operator<<(::log4cxx::helpers::CharMessageBuffer & os, const QString & s);
|
---|
| 54 | /// Output stream ::log4cxx::helpers::MessageBuffer operator for QString
|
---|
| 55 | PACPUSLIB_API ::log4cxx::helpers::CharMessageBuffer & operator<<(::log4cxx::helpers::MessageBuffer & os, const QString & s);
|
---|
| 56 |
|
---|
| 57 | #else
|
---|
| 58 | /// Declares a log4cxx logger
|
---|
| 59 | ///
|
---|
| 60 | /// @param name Name of the logger, displayed when logging a message.
|
---|
[109] | 61 | #define DECLARE_STATIC_LOGGER(name)
|
---|
[73] | 62 | /// Logs a message at TRACE level using default logger
|
---|
[112] | 63 | #define LOG_TRACE(message) do{;} while(false)
|
---|
[73] | 64 | /// Logs a message at DEBUG level using default logger
|
---|
[112] | 65 | #define LOG_DEBUG(message) do{;} while(false)
|
---|
[73] | 66 | /// Logs a message at INFO level using default logger
|
---|
[112] | 67 | #define LOG_INFO(message) do{;} while(false)
|
---|
[73] | 68 | /// Logs a message at WARN level using default logger
|
---|
[112] | 69 | #define LOG_WARN(message) do{;} while(false)
|
---|
[73] | 70 | /// Logs a message at ERROR level using default logger
|
---|
[112] | 71 | #define LOG_ERROR(message) do{;} while(false)
|
---|
[73] | 72 | /// Logs a message at FATAL level using default logger
|
---|
[112] | 73 | #define LOG_FATAL(message) do{;} while(false)
|
---|
[73] | 74 | #endif // PACPUS_USE_LOG
|
---|
| 75 |
|
---|
| 76 | #endif // DEF_PACPUS_LOG_H
|
---|