00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef OST_LOG_HH
00020 #define OST_LOG_HH
00021
00022 #include <ostream>
00023 #include <stack>
00024
00025 #include <ost/module_config.hh>
00026
00027 namespace ost {
00028
00029
00030 class DLLEXPORT_OST_BASE Logger {
00031 public:
00032 enum LogLevel {
00033 QUIET=0,
00034 NORMAL,
00035 VERBOSE,
00036 DEBUG,
00037 DUMP,
00038 TRACE
00039 };
00040
00041 void PushVerbosityLevel(int level);
00042 void PopVerbosityLevel();
00043
00044 std::ostream& operator()(enum LogLevel);
00045
00046 static Logger& Instance();
00047
00048 int GetLogLevel() const {return level_;}
00049
00050 protected:
00051 Logger();
00052 Logger(const Logger&);
00053 Logger& operator=(const Logger&);
00054
00055 private:
00056 int level_;
00057 std::stack<int> level_stack_;
00058 std::ostream null_;
00059 };
00060
00061 #define PUSH_VERBOSITY(n) ::ost::Logger::Instance().PushVerbosityLevel(n)
00062 #define POP_VERBOSITY(n) ::ost::Logger::Instance().PopVerbosityLevel()
00063
00064 #define LOG_ERROR(m) ::ost::Logger::Instance()(::ost::Logger::QUIET) << m;
00065 #define LOGN_ERROR(m) ::ost::Logger::Instance()(::ost::Logger::QUIET) << m << std::endl;
00066
00067 #define LOG_MESSAGE(m) if(::ost::Logger::Instance().GetLogLevel()>=::ost::Logger::NORMAL) {(::ost::Logger::Instance()(::ost::Logger::NORMAL)) << m ;}
00068 #define LOGN_MESSAGE(m) if(::ost::Logger::Instance().GetLogLevel()>=::ost::Logger::NORMAL) {(::ost::Logger::Instance()(::ost::Logger::NORMAL)) << m << std::endl;}
00069
00070 #define LOG_VERBOSE(m) if(::ost::Logger::Instance().GetLogLevel()>=::ost::Logger::VERBOSE) {(::ost::Logger::Instance()(::ost::Logger::VERBOSE)) << m ;}
00071 #define LOGN_VERBOSE(m) if(::ost::Logger::Instance().GetLogLevel()>=::ost::Logger::VERBOSE) {(::ost::Logger::Instance()(::ost::Logger::VERBOSE)) << m << std::endl;}
00072
00073 #define LOG_DEBUG(m) if(::ost::Logger::Instance().GetLogLevel()>=::ost::Logger::DEBUG) {(::ost::Logger::Instance()(::ost::Logger::DEBUG)) << m ;}
00074 #define LOGN_DEBUG(m) if(::ost::Logger::Instance().GetLogLevel()>=::ost::Logger::DEBUG) {(::ost::Logger::Instance()(::ost::Logger::DEBUG)) << m << std::endl;}
00075
00076 #ifdef NDEBUG
00077
00078 # define LOG_DUMP(m)
00079 # define LOGN_DUMP(m)
00080
00081 # define LOG_TRACE(m)
00082 # define LOGN_TRACE(m)
00083
00084 #else
00085
00086 # define LOG_DUMP(m) if(::ost::Logger::Instance().GetLogLevel()>=::ost::Logger::DUMP) {(::ost::Logger::Instance()(::ost::Logger::DUMP)) << m ;}
00087 # define LOGN_DUMP(m) if(::ost::Logger::Instance().GetLogLevel()>=::ost::Logger::DUMP) {(::ost::Logger::Instance()(::ost::Logger::DUMP)) << m << std::endl;}
00088
00089 # define LOG_TRACE(m) if(::ost::Logger::Instance().GetLogLevel()>=::ost::Logger::TRACE) {(::ost::Logger::Instance()(::ost::Logger::TRACE)) << m ;}
00090 # define LOGN_TRACE(m) if(::ost::Logger::Instance().GetLogLevel()>=::ost::Logger::TRACE) {(::ost::Logger::Instance()(::ost::Logger::TRACE)) << m << std::endl;}
00091
00092 #endif
00093
00094 }
00095
00096 #endif