Logger.h
Go to the documentation of this file.
1 
47 #ifndef CPR_LOGGER_H
48 #define CPR_LOGGER_H
49 
50 #include <iostream>
51 
52 namespace clearpath
53 {
54 
55  class Logger
56  {
57  private:
58  bool enabled;
59  int level;
60 
61  std::ostream *stream;
62 
63  std::ofstream *nullStream; //i.e /dev/null
64 
65  public:
66  enum logLevels
67  {
73  };
74  static const char *levelNames[]; // strings indexed by enumeration.
75 
76  private:
77  Logger();
78 
79  ~Logger();
80 
81  void close();
82 
83  public:
84  static Logger &instance();
85 
86  std::ostream &entry(enum logLevels level, const char *file = 0, int line = -1);
87 
88  void setEnabled(bool enabled);
89 
90  void setLevel(enum logLevels newLevel);
91 
92  void setStream(std::ostream *stream);
93 
94  void hookFatalSignals();
95 
96  friend void loggerTermHandler(int signal);
97  };
98 
99  void loggerTermHandler(int signal);
100 
101 }; // namespace clearpath
102 
103 // convenience macros
104 #define CPR_LOG(level) (clearpath::Logger::instance().entry((level), __FILE__, __LINE__ ))
105 #define CPR_ERR() CPR_LOG(clearpath::Logger::ERROR)
106 #define CPR_EXCEPT() (clearpath::Logger::instance().entry(clearpath::Logger::EXCEPTION))
107 #define CPR_WARN() CPR_LOG(clearpath::Logger::WARNING)
108 #define CPR_INFO() CPR_LOG(clearpath::Logger::INFO)
109 #define CPR_DTL() CPR_LOG(clearpath::Logger::DETAIL)
110 
111 #endif //CPR_LOGGER_H
112 
static const char * levelNames[]
Definition: Logger.h:74
static Logger & instance()
Definition: Logger.cpp:76
std::ostream & entry(enum logLevels level, const char *file=0, int line=-1)
Definition: Logger.cpp:105
friend void loggerTermHandler(int signal)
Definition: Logger.cpp:61
void setStream(std::ostream *stream)
Definition: Logger.cpp:137
std::ofstream * nullStream
Definition: Logger.h:63
void setLevel(enum logLevels newLevel)
Definition: Logger.cpp:132
std::ostream * stream
Definition: Logger.h:61
void hookFatalSignals()
Definition: Logger.cpp:143
void setEnabled(bool enabled)
Definition: Logger.cpp:127


husky_base
Author(s): Mike Purvis , Paul Bovbel
autogenerated on Fri Oct 2 2020 03:40:07