Logger.h
Go to the documentation of this file.
1 
38 #ifndef CPR_LOGGER_H
39 #define CPR_LOGGER_H
40 
41 #include <iostream>
42 
43 namespace sawyer
44 {
45 
46  class Logger
47  {
48  private:
49  bool enabled;
50  int level;
51 
52  std::ostream *stream;
53 
54  std::ofstream *nullStream; //i.e /dev/null
55 
56  public:
57  enum logLevels
58  {
64  };
65  static const char *levelNames[]; // strings indexed by enumeration.
66 
67  private:
68  Logger();
69 
70  ~Logger();
71 
72  void close();
73 
74  public:
75  static Logger &instance();
76 
77  std::ostream &entry(enum logLevels level, const char *file = 0, int line = -1);
78 
79  void setEnabled(bool enabled);
80 
81  void setLevel(enum logLevels newLevel);
82 
83  void setStream(std::ostream *stream);
84 
85  void hookFatalSignals();
86 
87  friend void loggerTermHandler(int signal);
88  };
89 
90  void loggerTermHandler(int signal);
91 
92 }; // namespace sawyer
93 
94 // convenience macros
95 #define CPR_LOG(level) (sawyer::Logger::instance().entry((level), __FILE__, __LINE__ ))
96 #define CPR_ERR() CPR_LOG(sawyer::Logger::ERROR)
97 #define CPR_EXCEPT() (sawyer::Logger::instance().entry(sawyer::Logger::EXCEPTION))
98 #define CPR_WARN() CPR_LOG(sawyer::Logger::WARNING)
99 #define CPR_INFO() CPR_LOG(sawyer::Logger::INFO)
100 #define CPR_DTL() CPR_LOG(sawyer::Logger::DETAIL)
101 
102 #endif //CPR_LOGGER_H
103 
std::ostream & entry(enum logLevels level, const char *file=0, int line=-1)
Definition: Logger.cpp:106
static Logger & instance()
Definition: Logger.cpp:77
void setEnabled(bool enabled)
Definition: Logger.cpp:128
void setStream(std::ostream *stream)
Definition: Logger.cpp:138
static const char * levelNames[]
Definition: Logger.h:65
void hookFatalSignals()
Definition: Logger.cpp:144
bool enabled
Definition: Logger.h:49
void close()
Definition: Logger.cpp:96
std::ostream * stream
Definition: Logger.h:52
friend void loggerTermHandler(int signal)
Definition: Logger.cpp:62
void setLevel(enum logLevels newLevel)
Definition: Logger.cpp:133
std::ofstream * nullStream
Definition: Logger.h:54


roch_base
Author(s): Mike Purvis , Paul Bovbel , Chen
autogenerated on Mon Jun 10 2019 14:41:13