source: pacpusframework/branches/0.0.x/include/Pacpus/kernel/Log.h

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

Added: PacpusException - base class for all exceptions. DbiteExceptions inherits from it.
Added: PacpusLibConfig.h - dllimport/dllexport clauses separated from pacpus.h.
Update: comments.

  • 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 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
17#include <Pacpus/kernel/PacpusLibConfig.h>
18
19namespace 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.
25static class PACPUSLIB_API LogConfigurator
26{
27public:
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
44 // https://devel.hds.utc.fr/projects/pacpus/ticket/55
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)
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) do{;} while(false)
64 /// Logs a message at DEBUG level using default logger
65 #define LOG_DEBUG(message) do{;} while(false)
66 /// Logs a message at INFO level using default logger
67 #define LOG_INFO(message) do{;} while(false)
68 /// Logs a message at WARN level using default logger
69 #define LOG_WARN(message) do{;} while(false)
70 /// Logs a message at ERROR level using default logger
71 #define LOG_ERROR(message) do{;} while(false)
72 /// Logs a message at FATAL level using default logger
73 #define LOG_FATAL(message) do{;} while(false)
74#endif // PACPUS_USE_LOG
75
76#endif // DEF_PACPUS_LOG_H
Note: See TracBrowser for help on using the repository browser.