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 #include <list>
00026
00027 namespace qpid {
00028 namespace log {
00029
00039 enum Level { trace, debug, info, notice, warning, error, critical };
00040 struct LevelTraits {
00041 static const int COUNT=critical+1;
00042
00046 static Level level(const char* name);
00047
00051 static Level level(const std::string& name) {
00052 return level(name.c_str());
00053 }
00054
00056 static const char* name(Level);
00057 };
00058
00077 enum Category { security, broker, management, protocol, system, ha, messaging,
00078 store, network, test, client, unspecified };
00079 struct CategoryTraits {
00080 static const int COUNT=unspecified+1;
00081
00084 static bool isCategory(const std::string& name);
00085
00089 static Category category(const char* name);
00090
00094 static Category category(const std::string& name) {
00095 return category(name.c_str());
00096 }
00097
00099 static const char* name(Category);
00100 };
00101
00102
00103 class CategoryFileNameHints {
00104 public:
00105 CategoryFileNameHints(){
00106 hintList.push_back(std::make_pair("AsynchIo", network));
00107 hintList.push_back(std::make_pair("TCP", network));
00108 hintList.push_back(std::make_pair("epoll", network));
00109 hintList.push_back(std::make_pair("Pollable", network));
00110 hintList.push_back(std::make_pair("Socket", network));
00111
00112 hintList.push_back(std::make_pair("Sasl", security));
00113 hintList.push_back(std::make_pair("Ssl", security));
00114 hintList.push_back(std::make_pair("Acl", security));
00115 hintList.push_back(std::make_pair("acl", security));
00116 hintList.push_back(std::make_pair("cyrus", security));
00117
00118 hintList.push_back(std::make_pair("amqp_", protocol));
00119 hintList.push_back(std::make_pair("framing", protocol));
00120
00121 hintList.push_back(std::make_pair("management", management));
00122 hintList.push_back(std::make_pair("qmf", management));
00123 hintList.push_back(std::make_pair("console", management));
00124 hintList.push_back(std::make_pair("Management", management));
00125
00126 hintList.push_back(std::make_pair("cluster", ha));
00127 hintList.push_back(std::make_pair("qpid/ha", ha));
00128 hintList.push_back(std::make_pair("qpid\\ha", ha));
00129 hintList.push_back(std::make_pair("replication", ha));
00130 hintList.push_back(std::make_pair("ClusterSafe", ha));
00131
00132 hintList.push_back(std::make_pair("broker", broker));
00133 hintList.push_back(std::make_pair("SessionState",broker));
00134 hintList.push_back(std::make_pair("DataDir", broker));
00135 hintList.push_back(std::make_pair("qpidd", broker));
00136 hintList.push_back(std::make_pair("xml", broker));
00137 hintList.push_back(std::make_pair("QpidBroker", broker));
00138
00139 hintList.push_back(std::make_pair("store", store));
00140
00141 hintList.push_back(std::make_pair("assert", system));
00142 hintList.push_back(std::make_pair("Exception", system));
00143 hintList.push_back(std::make_pair("sys", system));
00144 hintList.push_back(std::make_pair("SCM", system));
00145
00146 hintList.push_back(std::make_pair("tests", test));
00147
00148 hintList.push_back(std::make_pair("messaging", messaging));
00149 hintList.push_back(std::make_pair("types", messaging));
00150
00151 hintList.push_back(std::make_pair("client", client));
00152 }
00153
00154 static Category categoryOf(const char*const fName);
00155
00156 private:
00157 std::list<std::pair<const char* const, Category> > hintList;
00158 };
00159
00161 struct Statement {
00162 bool enabled;
00163 const char* file;
00164 int line;
00165 const char* function;
00166 Level level;
00167 Category category;
00168
00169 QPID_COMMON_EXTERN void log(const std::string& message);
00170 QPID_COMMON_EXTERN static void categorize(Statement& s);
00171
00172 struct Initializer {
00173 QPID_COMMON_EXTERN Initializer(Statement& s);
00174 Statement& statement;
00175 };
00176 };
00177
00179 #define QPID_LOG_STATEMENT_INIT_CAT(LEVEL, CATEGORY) \
00180 { 0, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION, (::qpid::log::LEVEL), \
00181 (::qpid::log::CATEGORY) }
00182
00183
00185 #define QPID_LOG_STATEMENT_INIT(LEVEL) \
00186 QPID_LOG_STATEMENT_INIT_CAT ( LEVEL , unspecified )
00187
00199 #define QPID_LOG_IF(LEVEL, TEST, MESSAGE) \
00200 do { \
00201 using ::qpid::log::Statement; \
00202 static Statement stmt_= QPID_LOG_STATEMENT_INIT(LEVEL); \
00203 static Statement::Initializer init_(stmt_); \
00204 if (stmt_.enabled && (TEST)) \
00205 stmt_.log(::qpid::Msg() << MESSAGE); \
00206 } while(0)
00207
00212 #define QPID_LOG_IF_CAT(LEVEL, CATEGORY, TEST, MESSAGE) \
00213 do { \
00214 using ::qpid::log::Statement; \
00215 static Statement stmt_= QPID_LOG_STATEMENT_INIT_CAT(LEVEL, CATEGORY); \
00216 static Statement::Initializer init_(stmt_); \
00217 if (stmt_.enabled && (TEST)) \
00218 stmt_.log(::qpid::Msg() << MESSAGE); \
00219 } while(0)
00220
00231 #define QPID_LOG_TEST(LEVEL, FLAG) \
00232 do { \
00233 using ::qpid::log::Statement; \
00234 static Statement stmt_= QPID_LOG_STATEMENT_INIT(LEVEL); \
00235 static Statement::Initializer init_(stmt_); \
00236 FLAG = stmt_.enabled; \
00237 } while(0)
00238
00249 #define QPID_LOG_TEST_CAT(LEVEL, CATEGORY, FLAG) \
00250 do { \
00251 using ::qpid::log::Statement; \
00252 static Statement stmt_= QPID_LOG_STATEMENT_INIT_CAT(LEVEL, CATEGORY); \
00253 static Statement::Initializer init_(stmt_); \
00254 FLAG = stmt_.enabled; \
00255 } while(0)
00256
00273 #define QPID_LOG(LEVEL, MESSAGE) QPID_LOG_IF(LEVEL, true, MESSAGE);
00274
00292 #define QPID_LOG_CAT(LEVEL, CATEGORY, MESSAGE) QPID_LOG_IF_CAT(LEVEL, CATEGORY, true, MESSAGE);
00293
00294 }}
00295
00296
00297
00298
00299 #endif