OpenAB  1.0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Log.hpp
Go to the documentation of this file.
1 /*
2  * This Source Code Form is subject to the terms of the Mozilla Public
3  * License, v. 2.0. If a copy of the MPL was not distributed with this
4  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
5  */
10 #ifndef _SYNC_LOG_HPP
11 #define _SYNC_LOG_HPP
12 
13 #include <sstream>
14 #include <iomanip>
15 #include <iostream>
16 
17 namespace OpenAB {
18 
22 class Logger
23 {
24  public:
28  Logger();
29 
33  virtual ~Logger();
34 
38  enum LogLevel
39  {
40  Fatal = 0 ,
43  Info,
47  };
48 
49  template <typename T>
51  {
52  oss<<data;
53  return *this;
54  }
55 
56  virtual Logger& operator<< (std::ostream& (*pf)(std::ostream&)) = 0;
57 
63  Logger& get(LogLevel l);
64 
69  static LogLevel& OutLevel();
70 
76  static Logger* getDefaultLogger();
77 
84  static void setDefaultLogger(Logger* logger);
85 
86  protected:
87  const char* toString(LogLevel l);
89  std::ostringstream oss;
90 };
91 
92 
93 
98 #define LOG_L(__level) \
99  if (OpenAB::Logger::OutLevel() >= __level) \
100  OpenAB::Logger::getDefaultLogger()->get(__level)
101 
105 #define LOG_VERBOSE() \
106  LOG_L(OpenAB::Logger::Verbose)
107 
111 #define LOG_DEBUG() \
112  LOG_L(OpenAB::Logger::Debug)
113 
117 #define LOG_ERROR() \
118  LOG_L(OpenAB::Logger::Error)
119 
123 #define LOG_FATAL() \
124  LOG_L(OpenAB::Logger::Fatal)
125 
129 #define LOG_WARNING() \
130  LOG_L(OpenAB::Logger::Warning)
131 
135 #define LOG_INFO() \
136  LOG_L(OpenAB::Logger::Info)
137 
141 #define LOG() \
142  LOG_INFO()
143 
147 #define LOG_FUNC() \
148  LOG_L(OpenAB::Logger::DebugF) << __FILE__ <<": " << (long long int)(__LINE__) << ": "<< __FUNCTION__ << std::endl
149 
152 }
153 #endif /* end _SYNC_LOG_HPP */
static void setDefaultLogger(Logger *logger)
Sets new default logger.
Definition: Log.cpp:55
Definition: Log.hpp:41
LogLevel
Definition: Log.hpp:38
Definition: Log.hpp:45
Definition: Log.hpp:42
Definition: Log.hpp:40
virtual ~Logger()
Destructor, virtual by default.
Definition: Log.cpp:65
Definition: Log.hpp:43
Logger()
Default constructor.
Definition: Log.cpp:60
static LogLevel & OutLevel()
Returns currently set LogLevel and allows to override it.
Definition: Log.cpp:90
Definition: Log.hpp:44
Definition: Log.hpp:46
Logger & operator<<(T data)
Definition: Log.hpp:50
Logger class, allows to override way in which messages from OpenAB will be logged.
Definition: Log.hpp:22
std::ostringstream oss
Definition: Log.hpp:89
const char * toString(LogLevel l)
Definition: Log.cpp:76
static Logger * getDefaultLogger()
Returns pointer to currently set default logger. There can be only one default logger set at the time...
Definition: Log.cpp:48
LogLevel level
Definition: Log.hpp:88