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


roch_base
Author(s): Mike Purvis , Paul Bovbel , Carl
autogenerated on Sat Jun 8 2019 20:32:33