Logger.h
Go to the documentation of this file.
00001 
00047 #ifndef CPR_LOGGER_H
00048 #define CPR_LOGGER_H
00049 
00050 #include <iostream>
00051 
00052 namespace clearpath
00053 {
00054 
00055   class Logger
00056   {
00057   private:
00058     bool enabled;
00059     int level;
00060 
00061     std::ostream *stream;
00062 
00063     std::ofstream *nullStream; //i.e /dev/null
00064 
00065   public:
00066     enum logLevels
00067     {
00068       ERROR_LEV,
00069       EXCEPTION,
00070       WARNING,
00071       INFO,
00072       DETAIL
00073     };
00074     static const char *levelNames[]; // strings indexed by enumeration. 
00075 
00076   private:
00077     Logger();
00078 
00079     ~Logger();
00080 
00081     void close();
00082 
00083   public:
00084     static Logger &instance();
00085 
00086     std::ostream &entry(enum logLevels level, const char *file = 0, int line = -1);
00087 
00088     void setEnabled(bool enabled);
00089 
00090     void setLevel(enum logLevels newLevel);
00091 
00092     void setStream(std::ostream *stream);
00093 
00094     void hookFatalSignals();
00095 
00096     friend void loggerTermHandler(int signal);
00097   };
00098 
00099   void loggerTermHandler(int signal);
00100 
00101 }; // namespace clearpath
00102 
00103 // convenience macros
00104 #define CPR_LOG(level) (clearpath::Logger::instance().entry((level), __FILE__, __LINE__ ))
00105 #define CPR_ERR()      CPR_LOG(clearpath::Logger::ERROR)
00106 #define CPR_EXCEPT()   (clearpath::Logger::instance().entry(clearpath::Logger::EXCEPTION))
00107 #define CPR_WARN()     CPR_LOG(clearpath::Logger::WARNING)
00108 #define CPR_INFO()     CPR_LOG(clearpath::Logger::INFO)
00109 #define CPR_DTL()      CPR_LOG(clearpath::Logger::DETAIL)
00110 
00111 #endif //CPR_LOGGER_H
00112 


husky_base
Author(s): Mike Purvis , Paul Bovbel
autogenerated on Sat Jun 8 2019 18:26:01