25 #ifndef LOG4CPLUS_LOGGING_MACROS_HEADER_
26 #define LOG4CPLUS_LOGGING_MACROS_HEADER_
30 #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE)
43 #define LOG4CPLUS_SUPPRESS_DOWHILE_WARNING() \
44 __pragma (warning (push)) \
45 __pragma (warning (disable:4127))
47 #define LOG4CPLUS_RESTORE_DOWHILE_WARNING() \
48 __pragma (warning (pop))
51 #define LOG4CPLUS_SUPPRESS_DOWHILE_WARNING()
52 #define LOG4CPLUS_RESTORE_DOWHILE_WARNING()
56 #define LOG4CPLUS_DOWHILE_NOTHING() \
57 LOG4CPLUS_SUPPRESS_DOWHILE_WARNING() \
59 LOG4CPLUS_RESTORE_DOWHILE_WARNING()
61 #if defined(LOG4CPLUS_DISABLE_FATAL) && !defined(LOG4CPLUS_DISABLE_ERROR)
62 #define LOG4CPLUS_DISABLE_ERROR
64 #if defined(LOG4CPLUS_DISABLE_ERROR) && !defined(LOG4CPLUS_DISABLE_WARN)
65 #define LOG4CPLUS_DISABLE_WARN
67 #if defined(LOG4CPLUS_DISABLE_WARN) && !defined(LOG4CPLUS_DISABLE_INFO)
68 #define LOG4CPLUS_DISABLE_INFO
70 #if defined(LOG4CPLUS_DISABLE_INFO) && !defined(LOG4CPLUS_DISABLE_DEBUG)
71 #define LOG4CPLUS_DISABLE_DEBUG
73 #if defined(LOG4CPLUS_DISABLE_DEBUG) && !defined(LOG4CPLUS_DISABLE_TRACE)
74 #define LOG4CPLUS_DISABLE_TRACE
105 return std::move (logger);
143 #undef LOG4CPLUS_MACRO_FUNCTION
144 #define LOG4CPLUS_MACRO_FUNCTION() nullptr
145 #if ! defined (LOG4CPLUS_DISABLE_FUNCTION_MACRO)
146 # if defined (LOG4CPLUS_HAVE_FUNCSIG_MACRO)
147 # undef LOG4CPLUS_MACRO_FUNCTION
148 # define LOG4CPLUS_MACRO_FUNCTION() __FUNCSIG__
149 # elif defined (LOG4CPLUS_HAVE_PRETTY_FUNCTION_MACRO)
150 # undef LOG4CPLUS_MACRO_FUNCTION
151 # define LOG4CPLUS_MACRO_FUNCTION() __PRETTY_FUNCTION__
152 # elif defined (LOG4CPLUS_HAVE_FUNCTION_MACRO)
153 # undef LOG4CPLUS_MACRO_FUNCTION
154 # define LOG4CPLUS_MACRO_FUNCTION() __FUNCTION__
155 # elif defined (LOG4CPLUS_HAVE_FUNC_SYMBOL)
156 # undef LOG4CPLUS_MACRO_FUNCTION
157 # define LOG4CPLUS_MACRO_FUNCTION() __func__
161 #undef LOG4CPLUS_MACRO_FILE
162 #define LOG4CPLUS_MACRO_FILE() nullptr
163 #if ! defined (LOG4CPLUS_DISABLE_FILE_MACRO)
164 # undef LOG4CPLUS_MACRO_FILE
165 # define LOG4CPLUS_MACRO_FILE() __FILE__
171 #define LOG4CPLUS_MACRO_TRACE_LOG_LEVEL(pred) \
172 LOG4CPLUS_UNLIKELY (pred)
173 #define LOG4CPLUS_MACRO_DEBUG_LOG_LEVEL(pred) \
174 LOG4CPLUS_UNLIKELY (pred)
175 #define LOG4CPLUS_MACRO_INFO_LOG_LEVEL(pred) \
176 LOG4CPLUS_LIKELY (pred)
177 #define LOG4CPLUS_MACRO_WARN_LOG_LEVEL(pred) \
178 LOG4CPLUS_LIKELY (pred)
179 #define LOG4CPLUS_MACRO_ERROR_LOG_LEVEL(pred) \
180 LOG4CPLUS_LIKELY (pred)
181 #define LOG4CPLUS_MACRO_FATAL_LOG_LEVEL(pred) \
182 LOG4CPLUS_LIKELY (pred)
186 #define LOG4CPLUS_MACRO_LOGLEVEL_PRED(pred, logLevel) \
187 LOG4CPLUS_MACRO_ ## logLevel (pred)
192 #if defined (LOG4CPLUS_MACRO_DISABLE_TLS)
193 # define LOG4CPLUS_MACRO_INSTANTIATE_OSTRINGSTREAM(var) \
194 log4cplus::tostringstream var
196 # define LOG4CPLUS_MACRO_INSTANTIATE_SNPRINTF_BUF(var) \
197 log4cplus::helpers::snprintf_buf var
200 # define LOG4CPLUS_MACRO_INSTANTIATE_OSTRINGSTREAM(var) \
201 log4cplus::tostringstream & var \
202 = log4cplus::detail::get_macro_body_oss ()
204 # define LOG4CPLUS_MACRO_INSTANTIATE_SNPRINTF_BUF(var) \
205 log4cplus::helpers::snprintf_buf & var \
206 = log4cplus::detail::get_macro_body_snprintf_buf ()
211 #define LOG4CPLUS_MACRO_BODY(logger, logEvent, logLevel) \
212 LOG4CPLUS_SUPPRESS_DOWHILE_WARNING() \
214 log4cplus::Logger const & _l \
215 = log4cplus::detail::macros_get_logger (logger); \
216 if (LOG4CPLUS_MACRO_LOGLEVEL_PRED ( \
217 _l.isEnabledFor (log4cplus::logLevel), logLevel)) { \
218 LOG4CPLUS_MACRO_INSTANTIATE_OSTRINGSTREAM (_log4cplus_buf); \
219 _log4cplus_buf << logEvent; \
220 log4cplus::detail::macro_forced_log (_l, \
221 log4cplus::logLevel, _log4cplus_buf.str(), \
222 LOG4CPLUS_MACRO_FILE (), __LINE__, \
223 LOG4CPLUS_MACRO_FUNCTION ()); \
226 LOG4CPLUS_RESTORE_DOWHILE_WARNING()
229 #define LOG4CPLUS_MACRO_STR_BODY(logger, logEvent, logLevel) \
230 LOG4CPLUS_SUPPRESS_DOWHILE_WARNING() \
232 log4cplus::Logger const & _l \
233 = log4cplus::detail::macros_get_logger (logger); \
234 if (LOG4CPLUS_MACRO_LOGLEVEL_PRED ( \
235 _l.isEnabledFor (log4cplus::logLevel), logLevel)) { \
236 log4cplus::detail::macro_forced_log (_l, \
237 log4cplus::logLevel, logEvent, \
238 LOG4CPLUS_MACRO_FILE (), __LINE__, \
239 LOG4CPLUS_MACRO_FUNCTION ()); \
242 LOG4CPLUS_RESTORE_DOWHILE_WARNING()
244 #define LOG4CPLUS_MACRO_FMT_BODY(logger, logLevel, ...) \
245 LOG4CPLUS_SUPPRESS_DOWHILE_WARNING() \
247 log4cplus::Logger const & _l \
248 = log4cplus::detail::macros_get_logger (logger); \
249 if (LOG4CPLUS_MACRO_LOGLEVEL_PRED ( \
250 _l.isEnabledFor (log4cplus::logLevel), logLevel)) { \
251 LOG4CPLUS_MACRO_INSTANTIATE_SNPRINTF_BUF (_snpbuf); \
252 log4cplus::tchar const * _logEvent \
253 = _snpbuf.print (__VA_ARGS__); \
254 log4cplus::detail::macro_forced_log (_l, \
255 log4cplus::logLevel, _logEvent, \
256 LOG4CPLUS_MACRO_FILE (), __LINE__, \
257 LOG4CPLUS_MACRO_FUNCTION ()); \
260 LOG4CPLUS_RESTORE_DOWHILE_WARNING()
268 #if !defined(LOG4CPLUS_DISABLE_TRACE)
269 #define LOG4CPLUS_TRACE_METHOD(logger, logEvent) \
270 log4cplus::TraceLogger _log4cplus_trace_logger(logger, logEvent, \
271 LOG4CPLUS_MACRO_FILE (), __LINE__, \
272 LOG4CPLUS_MACRO_FUNCTION ());
273 #define LOG4CPLUS_TRACE(logger, logEvent) \
274 LOG4CPLUS_MACRO_BODY (logger, logEvent, TRACE_LOG_LEVEL)
275 #define LOG4CPLUS_TRACE_STR(logger, logEvent) \
276 LOG4CPLUS_MACRO_STR_BODY (logger, logEvent, TRACE_LOG_LEVEL)
277 #define LOG4CPLUS_TRACE_FMT(logger, ...) \
278 LOG4CPLUS_MACRO_FMT_BODY (logger, TRACE_LOG_LEVEL, __VA_ARGS__)
281 #define LOG4CPLUS_TRACE_METHOD(logger, logEvent) LOG4CPLUS_DOWHILE_NOTHING()
282 #define LOG4CPLUS_TRACE(logger, logEvent) LOG4CPLUS_DOWHILE_NOTHING()
283 #define LOG4CPLUS_TRACE_STR(logger, logEvent) LOG4CPLUS_DOWHILE_NOTHING()
284 #define LOG4CPLUS_TRACE_FMT(logger, logFmt, ...) LOG4CPLUS_DOWHILE_NOTHING()
293 #if !defined(LOG4CPLUS_DISABLE_DEBUG)
294 #define LOG4CPLUS_DEBUG(logger, logEvent) \
295 LOG4CPLUS_MACRO_BODY (logger, logEvent, DEBUG_LOG_LEVEL)
296 #define LOG4CPLUS_DEBUG_STR(logger, logEvent) \
297 LOG4CPLUS_MACRO_STR_BODY (logger, logEvent, DEBUG_LOG_LEVEL)
298 #define LOG4CPLUS_DEBUG_FMT(logger, ...) \
299 LOG4CPLUS_MACRO_FMT_BODY (logger, DEBUG_LOG_LEVEL, __VA_ARGS__)
302 #define LOG4CPLUS_DEBUG(logger, logEvent) LOG4CPLUS_DOWHILE_NOTHING()
303 #define LOG4CPLUS_DEBUG_STR(logger, logEvent) LOG4CPLUS_DOWHILE_NOTHING()
304 #define LOG4CPLUS_DEBUG_FMT(logger, ...) LOG4CPLUS_DOWHILE_NOTHING()
313 #if !defined(LOG4CPLUS_DISABLE_INFO)
314 #define LOG4CPLUS_INFO(logger, logEvent) \
315 LOG4CPLUS_MACRO_BODY (logger, logEvent, INFO_LOG_LEVEL)
316 #define LOG4CPLUS_INFO_STR(logger, logEvent) \
317 LOG4CPLUS_MACRO_STR_BODY (logger, logEvent, INFO_LOG_LEVEL)
318 #define LOG4CPLUS_INFO_FMT(logger, ...) \
319 LOG4CPLUS_MACRO_FMT_BODY (logger, INFO_LOG_LEVEL, __VA_ARGS__)
322 #define LOG4CPLUS_INFO(logger, logEvent) LOG4CPLUS_DOWHILE_NOTHING()
323 #define LOG4CPLUS_INFO_STR(logger, logEvent) LOG4CPLUS_DOWHILE_NOTHING()
324 #define LOG4CPLUS_INFO_FMT(logger, ...) LOG4CPLUS_DOWHILE_NOTHING()
333 #if !defined(LOG4CPLUS_DISABLE_WARN)
334 #define LOG4CPLUS_WARN(logger, logEvent) \
335 LOG4CPLUS_MACRO_BODY (logger, logEvent, WARN_LOG_LEVEL)
336 #define LOG4CPLUS_WARN_STR(logger, logEvent) \
337 LOG4CPLUS_MACRO_STR_BODY (logger, logEvent, WARN_LOG_LEVEL)
338 #define LOG4CPLUS_WARN_FMT(logger, ...) \
339 LOG4CPLUS_MACRO_FMT_BODY (logger, WARN_LOG_LEVEL, __VA_ARGS__)
342 #define LOG4CPLUS_WARN(logger, logEvent) LOG4CPLUS_DOWHILE_NOTHING()
343 #define LOG4CPLUS_WARN_STR(logger, logEvent) LOG4CPLUS_DOWHILE_NOTHING()
344 #define LOG4CPLUS_WARN_FMT(logger, ...) LOG4CPLUS_DOWHILE_NOTHING()
353 #if !defined(LOG4CPLUS_DISABLE_ERROR)
354 #define LOG4CPLUS_ERROR(logger, logEvent) \
355 LOG4CPLUS_MACRO_BODY (logger, logEvent, ERROR_LOG_LEVEL)
356 #define LOG4CPLUS_ERROR_STR(logger, logEvent) \
357 LOG4CPLUS_MACRO_STR_BODY (logger, logEvent, ERROR_LOG_LEVEL)
358 #define LOG4CPLUS_ERROR_FMT(logger, ...) \
359 LOG4CPLUS_MACRO_FMT_BODY (logger, ERROR_LOG_LEVEL, __VA_ARGS__)
362 #define LOG4CPLUS_ERROR(logger, logEvent) LOG4CPLUS_DOWHILE_NOTHING()
363 #define LOG4CPLUS_ERROR_STR(logger, logEvent) LOG4CPLUS_DOWHILE_NOTHING()
364 #define LOG4CPLUS_ERROR_FMT(logger, ...) LOG4CPLUS_DOWHILE_NOTHING()
373 #if !defined(LOG4CPLUS_DISABLE_FATAL)
374 #define LOG4CPLUS_FATAL(logger, logEvent) \
375 LOG4CPLUS_MACRO_BODY (logger, logEvent, FATAL_LOG_LEVEL)
376 #define LOG4CPLUS_FATAL_STR(logger, logEvent) \
377 LOG4CPLUS_MACRO_STR_BODY (logger, logEvent, FATAL_LOG_LEVEL)
378 #define LOG4CPLUS_FATAL_FMT(logger, ...) \
379 LOG4CPLUS_MACRO_FMT_BODY (logger, FATAL_LOG_LEVEL, __VA_ARGS__)
382 #define LOG4CPLUS_FATAL(logger, logEvent) LOG4CPLUS_DOWHILE_NOTHING()
383 #define LOG4CPLUS_FATAL_STR(logger, logEvent) LOG4CPLUS_DOWHILE_NOTHING()
384 #define LOG4CPLUS_FATAL_FMT(logger, ...) LOG4CPLUS_DOWHILE_NOTHING()
389 #define LOG4CPLUS_ASSERT_STRINGIFY(X) #X
394 #define LOG4CPLUS_ASSERT(logger, condition) \
395 LOG4CPLUS_SUPPRESS_DOWHILE_WARNING() \
397 if (LOG4CPLUS_UNLIKELY(! (condition))) \
398 LOG4CPLUS_FATAL_STR ((logger), \
399 LOG4CPLUS_TEXT ("failed condition: ") \
400 LOG4CPLUS_TEXT (LOG4CPLUS_ASSERT_STRINGIFY (condition))); \
402 LOG4CPLUS_RESTORE_DOWHILE_WARNING()
This is the central class in the log4cplus package.
static Logger getInstance(const log4cplus::tstring &name)
Retrieve a logger with name name.
This header defines the Logger class and the logging macros.
LOG4CPLUS_EXPORT log4cplus::helpers::snprintf_buf & get_macro_body_snprintf_buf()
LOG4CPLUS_EXPORT void clear_tostringstream(tostringstream &)
Logger macros_get_logger(Logger const &logger)
LOG4CPLUS_EXPORT void macro_forced_log(log4cplus::Logger const &, log4cplus::LogLevel, log4cplus::tstring const &, char const *, int, char const *)
LOG4CPLUS_EXPORT log4cplus::tostringstream & get_macro_body_oss()
std::basic_string< tchar > tstring
std::basic_ostringstream< tchar > tostringstream
int LogLevel
Defines the minimum set of priorities recognized by the system, that is FATAL_LOG_LEVEL,...