From 3ee4d6aeac14d4dcf7df7cd531b7a2778714bdcd Mon Sep 17 00:00:00 2001 From: Alan Conway Date: Thu, 22 May 2008 15:02:11 +0000 Subject: Improved logging for session state. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@659127 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/src/qpid/log/Statement.h | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'cpp/src/qpid/log') diff --git a/cpp/src/qpid/log/Statement.h b/cpp/src/qpid/log/Statement.h index 18162971b0..f765df1cf4 100644 --- a/cpp/src/qpid/log/Statement.h +++ b/cpp/src/qpid/log/Statement.h @@ -78,6 +78,26 @@ struct Statement { #define QPID_LOG_STATEMENT_INIT(level) \ { 0, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION, (::qpid::log::level) } +/** + * Like QPID_LOG but computes an additional boolean test expression + * to determine if the message should be logged. Evaluation of both + * the test and message expressions occurs only if the requested log level + * is enabled. + *@param LEVEL severity Level for message, should be one of: + * debug, info, notice, warning, error, critical. NB no qpid::log:: prefix. + *@param TEST message is logged only if expression TEST evaluates to true. + *@param MESSAGE any object with an @eostream operator<<, or a sequence + * like of ostreamable objects separated by @e<<. + */ +#define QPID_LOG_IF(LEVEL, TEST, MESSAGE) \ + do { \ + using ::qpid::log::Statement; \ + static Statement stmt_= QPID_LOG_STATEMENT_INIT(LEVEL); \ + static Statement::Initializer init_(stmt_); \ + if (stmt_.enabled && (TEST)) \ + stmt_.log(::qpid::Msg() << MESSAGE); \ + } while(0) + /** * Macro for log statements. Example of use: * @code @@ -97,13 +117,7 @@ struct Statement { *@param MESSAGE any object with an @eostream operator<<, or a sequence * like of ostreamable objects separated by @e<<. */ -#define QPID_LOG(level, message) \ - do { \ - static ::qpid::log::Statement stmt_= QPID_LOG_STATEMENT_INIT(level); \ - static ::qpid::log::Statement::Initializer init_(stmt_); \ - if (stmt_.enabled) \ - stmt_.log(::qpid::Msg() << message); \ - } while(0) +#define QPID_LOG(LEVEL, MESSAGE) QPID_LOG_IF(LEVEL, true, MESSAGE); }} // namespace qpid::log -- cgit v1.2.1