| 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 | #include <Pacpus/kernel/PacpusLibConfig.h>
|
|---|
| 18 |
|
|---|
| 19 | namespace pacpus
|
|---|
| 20 | {
|
|---|
| 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 | static void configureLoggerWithFile(const char * configFilename);
|
|---|
| 32 | } logInitializer;
|
|---|
| 33 |
|
|---|
| 34 | } // namespace pacpus
|
|---|
| 35 |
|
|---|
| 36 | #if defined(PACPUS_USE_LOG)
|
|---|
| 37 | # include <boost/log/common.hpp>
|
|---|
| 38 | # include <boost/log/attributes/named_scope.hpp>
|
|---|
| 39 | # include <boost/log/core.hpp>
|
|---|
| 40 | # include <boost/log/sources/record_ostream.hpp>
|
|---|
| 41 | # include <boost/log/sources/severity_logger.hpp>
|
|---|
| 42 | # include <boost/log/trivial.hpp>
|
|---|
| 43 | # include <iosfwd>
|
|---|
| 44 |
|
|---|
| 45 | namespace pacpus
|
|---|
| 46 | {
|
|---|
| 47 |
|
|---|
| 48 | typedef boost::log::trivial::severity_level SeverityLevel;
|
|---|
| 49 | using boost::log::trivial::trace;
|
|---|
| 50 | using boost::log::trivial::debug;
|
|---|
| 51 | using boost::log::trivial::info;
|
|---|
| 52 | using boost::log::trivial::warning;
|
|---|
| 53 | using boost::log::trivial::error;
|
|---|
| 54 | using boost::log::trivial::fatal;
|
|---|
| 55 |
|
|---|
| 56 | BOOST_LOG_INLINE_GLOBAL_LOGGER_DEFAULT(gLogger, ::boost::log::sources::severity_logger_mt< ::pacpus::SeverityLevel>)
|
|---|
| 57 |
|
|---|
| 58 | } // namespace pacpus
|
|---|
| 59 |
|
|---|
| 60 | class QString;
|
|---|
| 61 | template< typename CharT, typename TraitsT >
|
|---|
| 62 | PACPUSLIB_API std::basic_ostream< CharT, TraitsT >& operator<< (std::basic_ostream< CharT, TraitsT >& strm, QString const& s);
|
|---|
| 63 |
|
|---|
| 64 | # define DECLARE_STATIC_LOGGER(name) //BOOST_LOG_NAMED_SCOPE(name)
|
|---|
| 65 | # define PACPUS_LOG_FUNCTION() BOOST_LOG_FUNCTION()
|
|---|
| 66 | # define PACPUS_LOG_NAMED_SCOPE(name) BOOST_LOG_NAMED_SCOPE(name)
|
|---|
| 67 | # define PACPUS_LOG(level, message) BOOST_LOG_SEV( ::pacpus::gLogger::get(), level) << message
|
|---|
| 68 | #else
|
|---|
| 69 | /// @param name Name of the logger, displayed when logging a message.
|
|---|
| 70 | # define DECLARE_STATIC_LOGGER(name)
|
|---|
| 71 | # define PACPUS_LOG_FUNCTION() ((void) 0)
|
|---|
| 72 | # define PACPUS_LOG_NAMED_SCOPE(name) ((void) 0)
|
|---|
| 73 | # define PACPUS_LOG(level, message) ((void) 0)
|
|---|
| 74 | #endif // PACPUS_USE_LOG
|
|---|
| 75 |
|
|---|
| 76 | /// Logs a message at TRACE level using default logger
|
|---|
| 77 | #define LOG_TRACE(message) PACPUS_LOG( ::pacpus::trace, message)
|
|---|
| 78 | /// Logs a message at DEBUG level using default logger
|
|---|
| 79 | #define LOG_DEBUG(message) PACPUS_LOG( ::pacpus::debug, message)
|
|---|
| 80 | /// Logs a message at INFO level using default logger
|
|---|
| 81 | #define LOG_INFO(message) PACPUS_LOG( ::pacpus::info, message)
|
|---|
| 82 | /// Logs a message at WARN level using default logger
|
|---|
| 83 | #define LOG_WARN(message) PACPUS_LOG( ::pacpus::warning, message)
|
|---|
| 84 | /// Logs a message at ERROR level using default logger
|
|---|
| 85 | #define LOG_ERROR(message) PACPUS_LOG( ::pacpus::error, message)
|
|---|
| 86 | /// Logs a message at FATAL level using default logger
|
|---|
| 87 | #define LOG_FATAL(message) PACPUS_LOG( ::pacpus::fatal, message)
|
|---|
| 88 |
|
|---|
| 89 | #endif // DEF_PACPUS_LOG_H
|
|---|