2
* Copyright (C) 2003, Tommi Maekitalo
4
* This library is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU Lesser General Public
6
* License as published by the Free Software Foundation; either
7
* version 2.1 of the License, or (at your option) any later version.
9
* As a special exception, you may use this file as part of a free
10
* software library without restriction. Specifically, if other files
11
* instantiate templates or use macros or inline functions from this
12
* file, or you compile this file and link it with other files to
13
* produce an executable, this file does not by itself cause the
14
* resulting executable to be covered by the GNU General Public
15
* License. This exception does not however invalidate any other
16
* reasons why the executable file might be covered by the GNU Library
17
* General Public License.
19
* This library is distributed in the hope that it will be useful,
20
* but WITHOUT ANY WARRANTY; without even the implied warranty of
21
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22
* Lesser General Public License for more details.
24
* You should have received a copy of the GNU Lesser General Public
25
* License along with this library; if not, write to the Free Software
26
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
29
#ifndef CXXTOOLS_LOG_LOG4CPLUS_H
30
#define CXXTOOLS_LOG_LOG4CPLUS_H
32
#include <log4cplus/logger.h>
34
#define log_fatal_enabled() getLogger().isEnabledFor(::log4cplus::FATAL_LOG_LEVEL)
35
#define log_error_enabled() getLogger().isEnabledFor(::log4cplus::ERROR_LOG_LEVEL)
36
#define log_warn_enabled() getLogger().isEnabledFor(::log4cplus::WARN_LOG_LEVEL)
37
#define log_info_enabled() getLogger().isEnabledFor(::log4cplus::INFO_LOG_LEVEL)
38
#define log_debug_enabled() getLogger().isEnabledFor(::log4cplus::DEBUG_LOG_LEVEL)
39
#define log_trace_enabled() getLogger().isEnabledFor(::log4cplus::TRACE_LOG_LEVEL)
41
#define log_xxxx(level, expr) \
43
if (getLogger().getRoot().getAllAppenders().size() > 0) \
45
LOG4CPLUS_ ## level (getLogger(), expr) \
49
#define log_fatal(expr) log_xxxx(FATAL, expr)
50
#define log_error(expr) log_xxxx(ERROR, expr)
51
#define log_warn(expr) log_xxxx(WARN, expr)
52
#define log_info(expr) log_xxxx(INFO, expr)
53
#define log_debug(expr) log_xxxx(DEBUG, expr)
54
#define log_trace(expr) \
55
::cxxtools::log4cplus_tracer tracer ## __LINE__ (getLogger()); \
56
if (log_trace_enabled()) \
58
tracer ## __LINE__ .logentry() << expr; \
59
tracer ## __LINE__ .enter(); \
62
#define log_define(category) \
63
static inline log4cplus::Logger& getLogger() \
65
static log4cplus::Logger tntlogger = log4cplus::Logger::getInstance(category); \
71
class log4cplus_tracer
74
std::ostringstream* msg;
76
log4cplus::Logger& getLogger() { return l; }
79
log4cplus_tracer(::log4cplus::Logger& l_)
84
if (msg && log_trace_enabled())
85
LOG4CPLUS_TRACE(l, "EXIT " << msg->str());
88
std::ostream& logentry()
91
msg = new std::ostringstream();
97
if (msg && log_trace_enabled())
98
LOG4CPLUS_TRACE(l, "ENTER " << msg->str());
103
#endif // CXXTOOLS_LOG_LOG4CPLUS_H