Logging.h
Go to the documentation of this file.
1 
20 #ifndef LOGGING_H_3B1A3A0F
21 #define LOGGING_H_3B1A3A0F
22 
23 #include "uscxml/Common.h"
24 #include "uscxml/messages/Data.h"
25 #include "uscxml/messages/Event.h"
26 
27 #include <memory>
28 
29 #define LOG(logger, lvl) logger.log(lvl)
30 #define LOG2(logger, lvl, thing) logger.log(lvl, thing)
31 #define LOGD(lvl) uscxml::Logger::getDefault().log(lvl)
32 #define LOGD2(lvl, thing) uscxml::Logger::getDefault().log(lvl, thing);
33 
34 namespace uscxml {
35 
36 enum LogSeverity {
37  USCXML_SCXML,
38  USCXML_TRACE,
39  USCXML_DEBUG,
40  USCXML_INFO,
41  USCXML_LOG, // from log element
42  USCXML_VERBATIM, // no additional decorations
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:94
Definition: Logging.h:69
Definition: Data.h:44