1 // Module: Log4CPLUS
2 // File: loggingmacros.h
3 // Created: 8/2003
4 // Author: Tad E. Smith
5 //
6 //
7 // Copyright (C) Tad E. Smith All rights reserved.
8 //
9 // This software is published under the terms of the Apache Software
10 // License version 1.1, a copy of which has been included with this
11 // distribution in the LICENSE.APL file.
12 //
13
14 /** @file
15 * This header defines the logging macros. */
16
17 #ifndef _LOG4CPLUS_LOGGING_MACROS_HEADER_
18 #define _LOG4CPLUS_LOGGING_MACROS_HEADER_
19
20 #if defined(LOG4CPLUS_DISABLE_FATAL) && !defined(LOG4CPLUS_DISABLE_ERROR)
21 #define LOG4CPLUS_DISABLE_ERROR
22 #endif
23 #if defined(LOG4CPLUS_DISABLE_ERROR) && !defined(LOG4CPLUS_DISABLE_WARN)
24 #define LOG4CPLUS_DISABLE_WARN
25 #endif
26 #if defined(LOG4CPLUS_DISABLE_WARN) && !defined(LOG4CPLUS_DISABLE_INFO)
27 #define LOG4CPLUS_DISABLE_INFO
28 #endif
29 #if defined(LOG4CPLUS_DISABLE_INFO) && !defined(LOG4CPLUS_DISABLE_DEBUG)
30 #define LOG4CPLUS_DISABLE_DEBUG
31 #endif
32 #if defined(LOG4CPLUS_DISABLE_DEBUG) && !defined(LOG4CPLUS_DISABLE_TRACE)
33 #define LOG4CPLUS_DISABLE_TRACE
34 #endif
35
36
37 /**
38 * @def LOG4CPLUS_TRACE(logger, logEvent) This macro creates a TraceLogger
39 * to log a TRACE_LOG_LEVEL message to <code>logger</code> upon entry and
40 * exiting of a method.
41 * <code>logEvent</code> will be streamed into an <code>ostream</code>.
42 */
43 #if !defined(LOG4CPLUS_DISABLE_TRACE)
44 #define LOG4CPLUS_TRACE_METHOD(logger, logEvent) \
45 log4cplus::TraceLogger _log4cplus_trace_logger(logger, logEvent, __FILE__, __LINE__);
46 #define LOG4CPLUS_TRACE(logger, logEvent) \
47 do { \
48 if(logger.isEnabledFor(log4cplus::TRACE_LOG_LEVEL)) { \
49 log4cplus::tostringstream _log4cplus_buf; \
50 _log4cplus_buf << logEvent; \
51 logger.forcedLog(log4cplus::TRACE_LOG_LEVEL, _log4cplus_buf.str(), __FILE__, __LINE__); \
52 } \
53 } while(0);
54 #define LOG4CPLUS_TRACE_STR(logger, logEvent) \
55 do { \
56 if(logger.isEnabledFor(log4cplus::TRACE_LOG_LEVEL)) { \
57 logger.forcedLog(log4cplus::TRACE_LOG_LEVEL, logEvent, __FILE__, __LINE__); \
58 } \
59 } while(0);
60 #else
61 #define LOG4CPLUS_TRACE_METHOD(logger, logEvent)
62 #define LOG4CPLUS_TRACE(logger, logEvent)
63 #define LOG4CPLUS_TRACE_STR(logger, logEvent)
64 #endif
65
66 /**
67 * @def LOG4CPLUS_DEBUG(logger, logEvent) This macro is used to log a
68 * DEBUG_LOG_LEVEL message to <code>logger</code>.
69 * <code>logEvent</code> will be streamed into an <code>ostream</code>.
70 */
71 #if !defined(LOG4CPLUS_DISABLE_DEBUG)
72 #define LOG4CPLUS_DEBUG(logger, logEvent) \
73 do { \
74 if(logger.isEnabledFor(log4cplus::DEBUG_LOG_LEVEL)) { \
75 log4cplus::tostringstream _log4cplus_buf; \
76 _log4cplus_buf << logEvent; \
77 logger.forcedLog(log4cplus::DEBUG_LOG_LEVEL, _log4cplus_buf.str(), __FILE__, __LINE__); \
78 } \
79 } while(0);
80 #define LOG4CPLUS_DEBUG_STR(logger, logEvent) \
81 do { \
82 if(logger.isEnabledFor(log4cplus::DEBUG_LOG_LEVEL)) { \
83 logger.forcedLog(log4cplus::DEBUG_LOG_LEVEL, logEvent, __FILE__, __LINE__); \
84 } \
85 } while(0);
86 #else
87 #define LOG4CPLUS_DEBUG(logger, logEvent)
88 #define LOG4CPLUS_DEBUG_STR(logger, logEvent)
89 #endif
90
91 /**
92 * @def LOG4CPLUS_INFO(logger, logEvent) This macro is used to log a
93 * INFO_LOG_LEVEL message to <code>logger</code>.
94 * <code>logEvent</code> will be streamed into an <code>ostream</code>.
95 */
96 #if !defined(LOG4CPLUS_DISABLE_INFO)
97 #define LOG4CPLUS_INFO(logger, logEvent) \
98 do { \
99 if(logger.isEnabledFor(log4cplus::INFO_LOG_LEVEL)) { \
100 log4cplus::tostringstream _log4cplus_buf; \
101 _log4cplus_buf << logEvent; \
102 logger.forcedLog(log4cplus::INFO_LOG_LEVEL, _log4cplus_buf.str(), __FILE__, __LINE__); \
103 } \
104 } while(0);
105 #define LOG4CPLUS_INFO_STR(logger, logEvent) \
106 do { \
107 if(logger.isEnabledFor(log4cplus::INFO_LOG_LEVEL)) { \
108 logger.forcedLog(log4cplus::INFO_LOG_LEVEL, logEvent, __FILE__, __LINE__); \
109 } \
110 } while(0);
111 #else
112 #define LOG4CPLUS_INFO(logger, logEvent)
113 #define LOG4CPLUS_INFO_STR(logger, logEvent)
114 #endif
115
116 /**
117 * @def LOG4CPLUS_WARN(logger, logEvent) This macro is used to log a
118 * WARN_LOG_LEVEL message to <code>logger</code>.
119 * <code>logEvent</code> will be streamed into an <code>ostream</code>.
120 */
121 #if !defined(LOG4CPLUS_DISABLE_WARN)
122 #define LOG4CPLUS_WARN(logger, logEvent) \
123 do { \
124 if(logger.isEnabledFor(log4cplus::WARN_LOG_LEVEL)) { \
125 log4cplus::tostringstream _log4cplus_buf; \
126 _log4cplus_buf << logEvent; \
127 logger.forcedLog(log4cplus::WARN_LOG_LEVEL, _log4cplus_buf.str(), __FILE__, __LINE__); \
128 } \
129 } while(0);
130 #define LOG4CPLUS_WARN_STR(logger, logEvent) \
131 do { \
132 if(logger.isEnabledFor(log4cplus::WARN_LOG_LEVEL)) { \
133 logger.forcedLog(log4cplus::WARN_LOG_LEVEL, logEvent, __FILE__, __LINE__); \
134 } \
135 } while(0);
136 #else
137 #define LOG4CPLUS_WARN(logger, logEvent)
138 #define LOG4CPLUS_WARN_STR(logger, logEvent)
139 #endif
140
141 /**
142 * @def LOG4CPLUS_ERROR(logger, logEvent) This macro is used to log a
143 * ERROR_LOG_LEVEL message to <code>logger</code>.
144 * <code>logEvent</code> will be streamed into an <code>ostream</code>.
145 */
146 #if !defined(LOG4CPLUS_DISABLE_ERROR)
147 #define LOG4CPLUS_ERROR(logger, logEvent) \
148 do { \
149 if(logger.isEnabledFor(log4cplus::ERROR_LOG_LEVEL)) { \
150 log4cplus::tostringstream _log4cplus_buf; \
151 _log4cplus_buf << logEvent; \
152 logger.forcedLog(log4cplus::ERROR_LOG_LEVEL, _log4cplus_buf.str(), __FILE__, __LINE__); \
153 } \
154 } while(0);
155 #define LOG4CPLUS_ERROR_STR(logger, logEvent) \
156 do { \
157 if(logger.isEnabledFor(log4cplus::ERROR_LOG_LEVEL)) { \
158 logger.forcedLog(log4cplus::ERROR_LOG_LEVEL, logEvent, __FILE__, __LINE__); \
159 } \
160 } while(0);
161 #else
162 #define LOG4CPLUS_ERROR(logger, logEvent)
163 #define LOG4CPLUS_ERROR_STR(logger, logEvent)
164 #endif
165
166 /**
167 * @def LOG4CPLUS_FATAL(logger, logEvent) This macro is used to log a
168 * FATAL_LOG_LEVEL message to <code>logger</code>.
169 * <code>logEvent</code> will be streamed into an <code>ostream</code>.
170 */
171 #if !defined(LOG4CPLUS_DISABLE_FATAL)
172 #define LOG4CPLUS_FATAL(logger, logEvent) \
173 do { \
174 if(logger.isEnabledFor(log4cplus::FATAL_LOG_LEVEL)) { \
175 log4cplus::tostringstream _log4cplus_buf; \
176 _log4cplus_buf << logEvent; \
177 logger.forcedLog(log4cplus::FATAL_LOG_LEVEL, _log4cplus_buf.str(), __FILE__, __LINE__); \
178 } \
179 } while(0);
180 #define LOG4CPLUS_FATAL_STR(logger, logEvent) \
181 do { \
182 if(logger.isEnabledFor(log4cplus::FATAL_LOG_LEVEL)) { \
183 logger.forcedLog(log4cplus::FATAL_LOG_LEVEL, logEvent, __FILE__, __LINE__); \
184 } \
185 } while(0);
186 #else
187 #define LOG4CPLUS_FATAL(logger, logEvent)
188 #define LOG4CPLUS_FATAL_STR(logger, logEvent)
189 #endif
190
191 #endif /* _LOG4CPLUS_LOGGING_MACROS_HEADER_ */
syntax highlighted by Code2HTML, v. 0.9.1