Apache Qpid - AMQP Messaging for Java JMS, C++, Python, Ruby, and .NET Apache Qpid Documentation
qpid/log/Statement.h
Go to the documentation of this file.
00001 #ifndef STATEMENT_H
00002 #define STATEMENT_H
00003 
00004 /*
00005  *
00006  * Copyright (c) 2006 The Apache Software Foundation
00007  *
00008  * Licensed under the Apache License, Version 2.0 (the "License");
00009  * you may not use this file except in compliance with the License.
00010  * You may obtain a copy of the License at
00011  *
00012  *    http://www.apache.org/licenses/LICENSE-2.0
00013  *
00014  * Unless required by applicable law or agreed to in writing, software
00015  * distributed under the License is distributed on an "AS IS" BASIS,
00016  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00017  * See the License for the specific language governing permissions and
00018  * limitations under the License.
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 
00078 enum Category { security, broker, management, protocol, system, ha, messaging,
00079     store, network, test, client, model, unspecified };
00080 struct CategoryTraits {
00081     static const int COUNT=unspecified+1;
00082 
00085     static bool isCategory(const std::string& name);
00086 
00090     static Category category(const char* name);
00091 
00095     static  Category category(const std::string& name) {
00096         return category(name.c_str());
00097     }
00098 
00100     static const char* name(Category);
00101 };
00102 
00103 
00104 class CategoryFileNameHints {
00105 public:
00106     CategoryFileNameHints(){
00107         hintList.push_back(std::make_pair("AsynchIo",    network));
00108         hintList.push_back(std::make_pair("TCP",         network));
00109         hintList.push_back(std::make_pair("epoll",       network));
00110         hintList.push_back(std::make_pair("Pollable",    network));
00111         hintList.push_back(std::make_pair("Socket",      network));
00112 
00113         hintList.push_back(std::make_pair("Sasl",        security));
00114         hintList.push_back(std::make_pair("Ssl",         security));
00115         hintList.push_back(std::make_pair("Acl",         security));
00116         hintList.push_back(std::make_pair("acl",         security));
00117         hintList.push_back(std::make_pair("cyrus",       security));
00118 
00119         hintList.push_back(std::make_pair("amqp_",       protocol));
00120         hintList.push_back(std::make_pair("framing",     protocol));
00121 
00122         hintList.push_back(std::make_pair("management",  management));
00123         hintList.push_back(std::make_pair("qmf",         management));
00124         hintList.push_back(std::make_pair("console",     management));
00125         hintList.push_back(std::make_pair("Management",  management));
00126 
00127         hintList.push_back(std::make_pair("cluster",     ha));
00128         hintList.push_back(std::make_pair("qpid/ha",     ha));
00129         hintList.push_back(std::make_pair("qpid\\ha",    ha));
00130         hintList.push_back(std::make_pair("replication", ha));
00131         hintList.push_back(std::make_pair("ClusterSafe", ha));
00132 
00133         hintList.push_back(std::make_pair("broker",      broker));
00134         hintList.push_back(std::make_pair("SessionState",broker));
00135         hintList.push_back(std::make_pair("DataDir",     broker));
00136         hintList.push_back(std::make_pair("qpidd",       broker));
00137         hintList.push_back(std::make_pair("xml",         broker));
00138         hintList.push_back(std::make_pair("QpidBroker",  broker));
00139 
00140         hintList.push_back(std::make_pair("store",       store));
00141 
00142         hintList.push_back(std::make_pair("assert",      system));
00143         hintList.push_back(std::make_pair("Exception",   system));
00144         hintList.push_back(std::make_pair("sys",         system));
00145         hintList.push_back(std::make_pair("SCM",         system));
00146 
00147         hintList.push_back(std::make_pair("tests",       test));
00148 
00149         hintList.push_back(std::make_pair("messaging",   messaging));
00150         hintList.push_back(std::make_pair("types",       messaging));
00151 
00152         hintList.push_back(std::make_pair("client",      client));
00153     }
00154 
00155     static Category categoryOf(const char*const fName);
00156 
00157 private:
00158     std::list<std::pair<const char* const, Category> > hintList;
00159 };
00160 
00162 struct Statement {
00163     bool enabled;
00164     const char* file;
00165     int line;
00166     const char* function;
00167     Level level;
00168     Category category;
00169 
00170     QPID_COMMON_EXTERN void log(const std::string& message);
00171     QPID_COMMON_EXTERN static void categorize(Statement& s);
00172 
00173     struct Initializer {
00174         QPID_COMMON_EXTERN Initializer(Statement& s);
00175         Statement& statement;
00176     };
00177 };
00178 
00180 #define QPID_LOG_STATEMENT_INIT_CAT(LEVEL, CATEGORY) \
00181 { 0, __FILE__, __LINE__,  BOOST_CURRENT_FUNCTION, (::qpid::log::LEVEL), \
00182 (::qpid::log::CATEGORY) }
00183 
00184 
00186 #define QPID_LOG_STATEMENT_INIT(LEVEL) \
00187 QPID_LOG_STATEMENT_INIT_CAT ( LEVEL , unspecified )
00188 
00200 #define QPID_LOG_IF(LEVEL, TEST, MESSAGE)                       \
00201     do {                                                        \
00202         using ::qpid::log::Statement;                           \
00203         static Statement stmt_= QPID_LOG_STATEMENT_INIT(LEVEL); \
00204         static Statement::Initializer init_(stmt_);             \
00205         if (stmt_.enabled && (TEST))                            \
00206             stmt_.log(::qpid::Msg() << MESSAGE);                \
00207     } while(0)
00208 
00213 #define QPID_LOG_IF_CAT(LEVEL, CATEGORY, TEST, MESSAGE)         \
00214     do {                                                        \
00215         using ::qpid::log::Statement;                           \
00216         static Statement stmt_= QPID_LOG_STATEMENT_INIT_CAT(LEVEL, CATEGORY); \
00217         static Statement::Initializer init_(stmt_);             \
00218         if (stmt_.enabled && (TEST))                            \
00219             stmt_.log(::qpid::Msg() << MESSAGE);                \
00220     } while(0)
00221 
00232 #define QPID_LOG_TEST(LEVEL, FLAG)                              \
00233     do {                                                        \
00234         using ::qpid::log::Statement;                           \
00235         static Statement stmt_= QPID_LOG_STATEMENT_INIT(LEVEL); \
00236         static Statement::Initializer init_(stmt_);             \
00237         FLAG = stmt_.enabled;                                   \
00238     } while(0)
00239 
00250     #define QPID_LOG_TEST_CAT(LEVEL, CATEGORY, FLAG)                \
00251     do {                                                        \
00252         using ::qpid::log::Statement;                           \
00253         static Statement stmt_= QPID_LOG_STATEMENT_INIT_CAT(LEVEL, CATEGORY); \
00254         static Statement::Initializer init_(stmt_);             \
00255         FLAG = stmt_.enabled;                                   \
00256     } while(0)
00257 
00274 #define QPID_LOG(LEVEL, MESSAGE) QPID_LOG_IF(LEVEL, true, MESSAGE);
00275 
00293 #define QPID_LOG_CAT(LEVEL, CATEGORY, MESSAGE) QPID_LOG_IF_CAT(LEVEL, CATEGORY, true, MESSAGE);
00294 
00295 }} // namespace qpid::log
00296 
00297 
00298 
00299 
00300 #endif  

Qpid C++ API Reference
Generated on Wed Jan 9 2013 for Qpid C++ Client API by doxygen 1.7.5