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
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
00058 static int priority(Level);
00059 };
00060
00062 struct Statement {
00063 bool enabled;
00064 const char* file;
00065 int line;
00066 const char* function;
00067 Level level;
00068
00069 void log(const std::string& message);
00070
00071 struct Initializer {
00072 Initializer(Statement& s);
00073 Statement& statement;
00074 };
00075 };
00076
00078 #define QPID_LOG_STATEMENT_INIT(level) \
00079 { 0, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION, (::qpid::log::level) }
00080
00092 #define QPID_LOG_IF(LEVEL, TEST, MESSAGE) \
00093 do { \
00094 using ::qpid::log::Statement; \
00095 static Statement stmt_= QPID_LOG_STATEMENT_INIT(LEVEL); \
00096 static Statement::Initializer init_(stmt_); \
00097 if (stmt_.enabled && (TEST)) \
00098 stmt_.log(::qpid::Msg() << MESSAGE); \
00099 } while(0)
00100
00120 #define QPID_LOG(LEVEL, MESSAGE) QPID_LOG_IF(LEVEL, true, MESSAGE);
00121
00122 }}
00123
00124
00125
00126
00127 #endif