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 
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 
00077 enum Category { security, broker, management, protocol, system, ha, messaging,
00078     store, network, test, client, model, 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 
00103 struct Statement {
00104     bool enabled;
00105     const char* file;
00106     int line;
00107     const char* function;
00108     Level level;
00109     Category category;
00110 
00111     QPID_COMMON_EXTERN void log(const std::string& message);
00112     QPID_COMMON_EXTERN static void categorize(Statement& s);
00113 
00114     struct Initializer {
00115         QPID_COMMON_EXTERN Initializer(Statement& s);
00116         Statement& statement;
00117     };
00118 };
00119 
00121 #define QPID_LOG_STATEMENT_INIT_CAT(LEVEL, CATEGORY) \
00122 { 0, __FILE__, __LINE__,  BOOST_CURRENT_FUNCTION, (::qpid::log::LEVEL), \
00123 (::qpid::log::CATEGORY) }
00124 
00125 
00127 #define QPID_LOG_STATEMENT_INIT(LEVEL) \
00128 QPID_LOG_STATEMENT_INIT_CAT ( LEVEL , unspecified )
00129 
00141 #define QPID_LOG_IF(LEVEL, TEST, MESSAGE)                       \
00142     do {                                                        \
00143         using ::qpid::log::Statement;                           \
00144         static Statement stmt_= QPID_LOG_STATEMENT_INIT(LEVEL); \
00145         static Statement::Initializer init_(stmt_);             \
00146         if (stmt_.enabled && (TEST))                            \
00147             stmt_.log(::qpid::Msg() << MESSAGE);                \
00148     } while(0)
00149 
00154 #define QPID_LOG_IF_CAT(LEVEL, CATEGORY, TEST, MESSAGE)         \
00155     do {                                                        \
00156         using ::qpid::log::Statement;                           \
00157         static Statement stmt_= QPID_LOG_STATEMENT_INIT_CAT(LEVEL, CATEGORY); \
00158         static Statement::Initializer init_(stmt_);             \
00159         if (stmt_.enabled && (TEST))                            \
00160             stmt_.log(::qpid::Msg() << MESSAGE);                \
00161     } while(0)
00162 
00173 #define QPID_LOG_TEST(LEVEL, FLAG)                              \
00174     do {                                                        \
00175         using ::qpid::log::Statement;                           \
00176         static Statement stmt_= QPID_LOG_STATEMENT_INIT(LEVEL); \
00177         static Statement::Initializer init_(stmt_);             \
00178         FLAG = stmt_.enabled;                                   \
00179     } while(0)
00180 
00191     #define QPID_LOG_TEST_CAT(LEVEL, CATEGORY, FLAG)                \
00192     do {                                                        \
00193         using ::qpid::log::Statement;                           \
00194         static Statement stmt_= QPID_LOG_STATEMENT_INIT_CAT(LEVEL, CATEGORY); \
00195         static Statement::Initializer init_(stmt_);             \
00196         FLAG = stmt_.enabled;                                   \
00197     } while(0)
00198 
00215 #define QPID_LOG(LEVEL, MESSAGE) QPID_LOG_IF(LEVEL, true, MESSAGE);
00216 
00234 #define QPID_LOG_CAT(LEVEL, CATEGORY, MESSAGE) QPID_LOG_IF_CAT(LEVEL, CATEGORY, true, MESSAGE);
00235 
00236 }} // namespace qpid::log
00237 
00238 
00239 
00240 
00241 #endif  

Qpid C++ API Reference
Generated on Fri Aug 23 2013 for Qpid C++ Client API by doxygen 1.7.5