C API Documentation
rrLogger.h
1 #ifndef rrLoggerH
2 #define rrLoggerH
3 #include <sstream>
4 #include "rrExporter.h"
5 
6 
7 namespace Poco {
8 class Logger;
9 }
10 
11 namespace rr
12 {
13 
25 class RR_DECLSPEC LoggingBuffer
26 {
27 public:
28  LoggingBuffer(int level, const char* file, int line);
29 
34 
38  std::ostream &stream();
39 
40 private:
41  std::stringstream buffer;
42  int level;
43  const char* file;
44  int line;
45 };
46 
52 class RR_DECLSPEC Logger
53 {
54 public:
60  enum Level
61  {
62  LOG_CURRENT = 0,
63  LOG_FATAL = 1,
70  LOG_TRACE
71  };
72 
76  static void setLevel(int level = LOG_CURRENT);
77 
81  static int getLevel();
82 
86  static void disableLogging();
87 
91  static void disableConsoleLogging();
92 
96  static void enableConsoleLogging(int level = LOG_CURRENT);
97 
110  static void enableFileLogging(const std::string& fileName = "",
111  int level = LOG_CURRENT);
112 
116  static void disableFileLogging();
117 
121  static std::string getCurrentLevelAsString();
122 
126  static std::string getFileName();
127 
188  static void setFormattingPattern(const std::string &format);
189 
193  static std::string getFormattingPattern();
194 
198  static std::string levelToString(int level);
199 
203  static Level stringToLevel(const std::string& str);
204 
208  static bool getColoredOutput();
209 
213  static void setColoredOutput(bool);
214 
215 
253  static void setProperty(const std::string& name, const std::string& value);
254 
255 
262  static void log(Level level, const std::string& msg);
263 
264 #ifndef SWIG // don't expose this to SWIG
265 
277  static void setConsoleStream(std::ostream *os);
278 #endif
279 };
280 
284 enum LogLevel
285 {
286  lAny = Logger::LOG_ERROR,
287  lError = Logger::LOG_ERROR,
288  lWarning = Logger::LOG_WARNING,
289  lInfo = Logger::LOG_INFORMATION,
290  lDebug = Logger::LOG_DEBUG,
291  lDebug1 = Logger::LOG_TRACE,
292  lDebug2 = Logger::LOG_TRACE,
293  lDebug3 = Logger::LOG_TRACE,
294  lDebug4 = Logger::LOG_TRACE,
295  lDebug5 = Logger::LOG_TRACE,
296  lUser = Logger::LOG_TRACE
297 };
298 
305 RR_DECLSPEC Poco::Logger &getLogger();
306 
310 #define gLog Logger()
311 
312 #ifndef NO_LOGGER
313 #define Log(level) \
314  if (level > rr::Logger::getLevel()) { ; } \
315  else rr::LoggingBuffer(level, __FILE__, __LINE__).stream()
316 #else
317 #define Log(level) \
318  if (true) { }\
319  else \
320  LoggingBuffer(level, __FILE__, __LINE__)
321 #endif
322 
323 
324 } /* namespace rr */
325 
326 
327 #endif /* rrLoggerH */
Definition: rrLogger.h:53
static void disableConsoleLogging()
static void disableFileLogging()
static void disableLogging()
static void setLevel(int level=LOG_CURRENT)
static std::string getFileName()
static void log(Level level, const std::string &msg)
static bool getColoredOutput()
Level
Definition: rrLogger.h:61
@ LOG_TRACE
A debugging message.
Definition: rrLogger.h:70
@ LOG_INFORMATION
A notice, which is an information with just a higher priority.
Definition: rrLogger.h:68
@ LOG_CRITICAL
A fatal error. The application will most likely terminate. This is the highest priority.
Definition: rrLogger.h:64
@ LOG_NOTICE
A warning. An operation completed with an unexpected result.
Definition: rrLogger.h:67
@ LOG_WARNING
An error. An operation did not complete successfully, but the application as a whole is not affected.
Definition: rrLogger.h:66
@ LOG_DEBUG
An informational message, usually denoting the successful completion of an operation.
Definition: rrLogger.h:69
@ LOG_ERROR
A critical error. The application might not be able to continue running successfully.
Definition: rrLogger.h:65
static void setProperty(const std::string &name, const std::string &value)
static std::string getCurrentLevelAsString()
static std::string getFormattingPattern()
static std::string levelToString(int level)
static void setFormattingPattern(const std::string &format)
static void enableConsoleLogging(int level=LOG_CURRENT)
static void setColoredOutput(bool)
static Level stringToLevel(const std::string &str)
static void enableFileLogging(const std::string &fileName="", int level=LOG_CURRENT)
static void setConsoleStream(std::ostream *os)
static int getLevel()
Definition: rrLogger.h:26
std::ostream & stream()