[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 73 2013-01-10 16:56:42Z 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 |
|
---|
| 17 | // Includes, pacpus.
|
---|
| 18 | #include <Pacpus/kernel/pacpus.h>
|
---|
| 19 |
|
---|
| 20 | namespace pacpus {
|
---|
| 21 |
|
---|
| 22 | /// Static log facility initializer
|
---|
| 23 | ///
|
---|
| 24 | /// Uses Schwarz counter (nifty counter) idiom to initialize the log before
|
---|
| 25 | /// other static objects that could use the log.
|
---|
| 26 | static class PACPUSLIB_API LogConfigurator
|
---|
| 27 | {
|
---|
| 28 | public:
|
---|
| 29 | LogConfigurator();
|
---|
| 30 | ~LogConfigurator();
|
---|
| 31 |
|
---|
| 32 | static void configureLoggerWithFile(const char * configFilename);
|
---|
| 33 | } initializer; // using Schwarz/nifty counter idiom for static initialization
|
---|
| 34 |
|
---|
| 35 | } // namespace pacpus
|
---|
| 36 |
|
---|
| 37 | #ifdef PACPUS_USE_LOG
|
---|
| 38 | #include <log4cxx/logger.h>
|
---|
| 39 |
|
---|
| 40 | class QString;
|
---|
| 41 |
|
---|
| 42 | #define DECLARE_STATIC_LOGGER(name) \
|
---|
| 43 | static log4cxx::LoggerPtr logger(log4cxx::Logger::getLogger(name))
|
---|
| 44 |
|
---|
| 45 | #define LOG_TRACE(message) LOG4CXX_TRACE(logger, message)
|
---|
| 46 | #define LOG_DEBUG(message) LOG4CXX_DEBUG(logger, message)
|
---|
| 47 | #define LOG_INFO(message) LOG4CXX_INFO(logger, message)
|
---|
| 48 | #define LOG_WARN(message) LOG4CXX_WARN(logger, message)
|
---|
| 49 | #define LOG_ERROR(message) LOG4CXX_ERROR(logger, message)
|
---|
| 50 | #define LOG_FATAL(message) LOG4CXX_FATAL(logger, message)
|
---|
| 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.
|
---|
| 61 | #define DECLARE_STATIC_LOGGER(name)
|
---|
| 62 | /// Logs a message at TRACE level using default logger
|
---|
| 63 | #define LOG_TRACE(message)
|
---|
| 64 | /// Logs a message at DEBUG level using default logger
|
---|
| 65 | #define LOG_DEBUG(message)
|
---|
| 66 | /// Logs a message at INFO level using default logger
|
---|
| 67 | #define LOG_INFO(message)
|
---|
| 68 | /// Logs a message at WARN level using default logger
|
---|
| 69 | #define LOG_WARN(message)
|
---|
| 70 | /// Logs a message at ERROR level using default logger
|
---|
| 71 | #define LOG_ERROR(message)
|
---|
| 72 | /// Logs a message at FATAL level using default logger
|
---|
| 73 | #define LOG_FATAL(message)
|
---|
| 74 | #endif // PACPUS_USE_LOG
|
---|
| 75 |
|
---|
| 76 | #endif // DEF_PACPUS_LOG_H
|
---|