00001 #ifndef STATEMENT_H
00002 #define STATEMENT_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "qpid/Msg.h"
00023 #include "qpid/CommonImportExport.h"
00024 #include <boost/current_function.hpp>
00025
00026 namespace qpid {
00027 namespace log {
00028
00038 enum Level { trace, debug, info, notice, warning, error, critical };
00039 struct LevelTraits {
00040 static const int COUNT=critical+1;
00041
00045 static Level level(const char* name);
00046
00050 static Level level(const std::string& name) {
00051 return level(name.c_str());
00052 }
00053
00055 static const char* name(Level);
00056 };
00057
00059 struct Statement {
00060 bool enabled;
00061 const char* file;
00062 int line;
00063 const char* function;
00064 Level level;
00065
00066 QPID_COMMON_EXTERN void log(const std::string& message);
00067
00068 struct Initializer {
00069 QPID_COMMON_EXTERN Initializer(Statement& s);
00070 Statement& statement;
00071 };
00072 };
00073
00075 #define QPID_LOG_STATEMENT_INIT(level) \
00076 { 0, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION, (::qpid::log::level) }
00077
00089 #define QPID_LOG_IF(LEVEL, TEST, MESSAGE) \
00090 do { \
00091 using ::qpid::log::Statement; \
00092 static Statement stmt_= QPID_LOG_STATEMENT_INIT(LEVEL); \
00093 static Statement::Initializer init_(stmt_); \
00094 if (stmt_.enabled && (TEST)) \
00095 stmt_.log(::qpid::Msg() << MESSAGE); \
00096 } while(0)
00097
00113 #define QPID_LOG(LEVEL, MESSAGE) QPID_LOG_IF(LEVEL, true, MESSAGE);
00114
00115 }}
00116
00117
00118
00119
00120 #endif