source: pacpusframework/trunk/include/Pacpus/kernel/Log.h@ 236

Last change on this file since 236 was 236, checked in by Marek Kurdej, 11 years ago

Experimental: using global logger object instead of trivial logger. Added: stub for colored log output on Linux.

  • Property svn:executable set to *
File size: 3.2 KB
Line 
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
19namespace 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.
26static class PACPUSLIB_API LogConfigurator
27{
28public:
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 <iosfwd>
43
44namespace pacpus
45{
46 /// Trivial severity levels
47 /*PACPUSLIB_API*/ enum SeverityLevel
48 {
49 trace,
50 debug,
51 info,
52 warning,
53 error,
54 fatal
55 };
56
57 BOOST_LOG_INLINE_GLOBAL_LOGGER_DEFAULT(gLogger, ::boost::log::sources::severity_logger_mt< ::pacpus::SeverityLevel>)
58
59} // namespace pacpus
60
61class QString;
62template< typename CharT, typename TraitsT >
63PACPUSLIB_API std::basic_ostream< CharT, TraitsT >& operator<< (std::basic_ostream< CharT, TraitsT >& strm, QString const& s);
64
65# define DECLARE_STATIC_LOGGER(name) //BOOST_LOG_NAMED_SCOPE(name)
66# define PACPUS_LOG_FUNCTION() BOOST_LOG_FUNCTION()
67# define PACPUS_LOG_NAMED_SCOPE(name) BOOST_LOG_NAMED_SCOPE(name)
68# define PACPUS_LOG(level, message) BOOST_LOG_SEV( ::pacpus::gLogger::get(), level) << message
69#else
70/// @param name Name of the logger, displayed when logging a message.
71# define DECLARE_STATIC_LOGGER(name)
72# define PACPUS_LOG_FUNCTION() ((void) 0)
73# define PACPUS_LOG_NAMED_SCOPE(name) ((void) 0)
74# define PACPUS_LOG(level, message) ((void) 0)
75#endif // PACPUS_USE_LOG
76
77/// Logs a message at TRACE level using default logger
78#define LOG_TRACE(message) PACPUS_LOG( ::pacpus::trace, message)
79/// Logs a message at DEBUG level using default logger
80#define LOG_DEBUG(message) PACPUS_LOG( ::pacpus::debug, message)
81/// Logs a message at INFO level using default logger
82#define LOG_INFO(message) PACPUS_LOG( ::pacpus::info, message)
83/// Logs a message at WARN level using default logger
84#define LOG_WARN(message) PACPUS_LOG( ::pacpus::warning, message)
85/// Logs a message at ERROR level using default logger
86#define LOG_ERROR(message) PACPUS_LOG( ::pacpus::error, message)
87/// Logs a message at FATAL level using default logger
88#define LOG_FATAL(message) PACPUS_LOG( ::pacpus::fatal, message)
89
90#endif // DEF_PACPUS_LOG_H
Note: See TracBrowser for help on using the repository browser.