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

Last change on this file since 109 was 109, checked in by aschildk, 11 years ago

Fix macro definition

  • Property svn:keywords set to Id
File size: 3.0 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 109 2013-06-07 14:01:14Z aschildk $
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
20namespace 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.
26static class PACPUSLIB_API LogConfigurator
27{
28public:
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 /* https://devel.hds.utc.fr/projects/pacpus/ticket/55 */
46 #define LOG_TRACE(message) do{LOG4CXX_TRACE(logger, message);}while(0)
47 #define LOG_DEBUG(message) do{LOG4CXX_DEBUG(logger, message);}while(0)
48 #define LOG_INFO(message) do{LOG4CXX_INFO(logger, message);}while(0)
49 #define LOG_WARN(message) do{LOG4CXX_WARN(logger, message);}while(0)
50 #define LOG_ERROR(message) do{LOG4CXX_ERROR(logger, message);}while(0)
51 #define LOG_FATAL(message) do{LOG4CXX_FATAL(logger, message);}while(0)
52
53 /// Output stream ::log4cxx::helpers::CharMessageBuffer operator for QString
54 PACPUSLIB_API ::log4cxx::helpers::CharMessageBuffer & operator<<(::log4cxx::helpers::CharMessageBuffer & os, const QString & s);
55 /// Output stream ::log4cxx::helpers::MessageBuffer operator for QString
56 PACPUSLIB_API ::log4cxx::helpers::CharMessageBuffer & operator<<(::log4cxx::helpers::MessageBuffer & os, const QString & s);
57
58#else
59 /// Declares a log4cxx logger
60 ///
61 /// @param name Name of the logger, displayed when logging a message.
62 #define DECLARE_STATIC_LOGGER(name)
63 /// Logs a message at TRACE level using default logger
64 #define LOG_TRACE(message) do{;}while(0)
65 /// Logs a message at DEBUG level using default logger
66 #define LOG_DEBUG(message) do{;}while(0)
67 /// Logs a message at INFO level using default logger
68 #define LOG_INFO(message) do{;}while(0)
69 /// Logs a message at WARN level using default logger
70 #define LOG_WARN(message) do{;}while(0)
71 /// Logs a message at ERROR level using default logger
72 #define LOG_ERROR(message) do{;}while(0)
73 /// Logs a message at FATAL level using default logger
74 #define LOG_FATAL(message) do{;}while(0)
75#endif // PACPUS_USE_LOG
76
77#endif // DEF_PACPUS_LOG_H
Note: See TracBrowser for help on using the repository browser.