qpid/log/Statement.h Source File

Apache Qpid - AMQP Messaging for Java JMS, C++, Python, Ruby, and .NET | Apache Qpid Documentation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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
    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
    00108 #define QPID_LOG_TEST(LEVEL, FLAG)                              \
    00109     do {                                                        \
    00110         using ::qpid::log::Statement;                           \
    00111         static Statement stmt_= QPID_LOG_STATEMENT_INIT(LEVEL); \
    00112         static Statement::Initializer init_(stmt_);             \
    00113         FLAG = stmt_.enabled;                                   \
    00114     } while(0)
    00115
    00131 #define QPID_LOG(LEVEL, MESSAGE) QPID_LOG_IF(LEVEL, true, MESSAGE);
    00132
    00133 }} // namespace qpid::log
    00134
    00135
    00136
    00137
    00138 #endif