Logging.h
Go to the documentation of this file.
1 
20 #ifndef LOGGING_H_3B1A3A0F
21 #define LOGGING_H_3B1A3A0F
22 
23 #include "uscxml/config.h"
24 #include "uscxml/Common.h"
25 
26 #include "uscxml/messages/Data.h"
27 #include "uscxml/messages/Event.h"
28 
29 #include <memory>
30 
31 #define LOG(logger, lvl) logger.log(lvl)
32 #define LOG2(logger, lvl, thing) logger.log(lvl, thing)
33 #define LOGD(lvl) uscxml::Logger::getDefault().log(lvl)
34 #define LOGD2(lvl, thing) uscxml::Logger::getDefault().log(lvl, thing);
35 
36 namespace uscxml {
37 
38 enum LogSeverity {
39  USCXML_SCXML,
40  USCXML_TRACE,
41  USCXML_DEBUG,
42  USCXML_INFO,
43  USCXML_WARN,
44  USCXML_ERROR,
45  USCXML_FATAL
46 };
47 
48 class LoggerImpl;
49 
50 void log(LogSeverity severity, const Event& event);
51 void log(LogSeverity severity, const Data& data);
52 
53 class StreamLogger {
54 public:
55  std::ostream& operator<<(const std::string& message);
56  ~StreamLogger();
57 
58 protected:
59  StreamLogger(LogSeverity severity, std::shared_ptr<LoggerImpl> logger) : _severity(severity), _logger(logger) {}
60  StreamLogger(const StreamLogger& other) : _severity(other._severity), _logger(other._logger) {}
61 
62  LogSeverity _severity;
63  std::shared_ptr<LoggerImpl> _logger;
64  std::stringstream ss;
65 
66  friend class Logger;
67 };
68 
69 class USCXML_API Logger {
70 public:
72 
73  virtual void log(LogSeverity severity, const Event& event);
74  virtual void log(LogSeverity severity, const Data& data);
75  virtual void log(LogSeverity severity, const std::string& message);
76 
77  virtual StreamLogger log(LogSeverity severity);
78  static std::string severityToString(LogSeverity severity);
79 
80  static Logger getDefault();
81 
82  std::shared_ptr<LoggerImpl> getImpl() const;
83 protected:
84  std::shared_ptr<LoggerImpl> _impl;
85 
86 };
87 
88 }
89 
90 #endif /* end of include guard: LOGGING_H_3B1A3A0F */
Definition: Breakpoint.cpp:26
#define PIMPL_OPERATORS(type)
The usual operators as required for the PIMPL pattern.
Definition: Common.h:68
Definition: Logging.h:53
Definition: Event.h:84
Definition: Logging.h:69
Definition: Data.h:43