/usr/share/cruisecontrol-bin-2.6.1/projects/qpid-trunk/cpp/src/qpid/log/Statement.h

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 
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 
00100 #define QPID_LOG(level, message)                                        \
00101     do {                                                                \
00102         static ::qpid::log::Statement stmt_= QPID_LOG_STATEMENT_INIT(level); \
00103         static ::qpid::log::Statement::Initializer init_(stmt_);        \
00104         if (stmt_.enabled)                                              \
00105             stmt_.log(::qpid::Msg() << message);                        \
00106     } while(0)
00107 
00108 }} // namespace qpid::log
00109 
00110 
00111 
00112 
00113 #endif  

Generated on Thu Apr 10 11:08:18 2008 for Qpid by  doxygen 1.4.7