1 #ifndef LOGGING_MACROS_GROUP
2 #define LOGGING_MACROS_GROUP
4 /*****************************************************************************\
6 * Name : logging macros *
7 * Author : Chris Koeritz *
9 *******************************************************************************
10 * Copyright (c) 1996-$now By Author. This program is free software; you can *
11 * redistribute it and/or modify it under the terms of the GNU General Public *
12 * License as published by the Free Software Foundation; either version 2 of *
13 * the License or (at your option) any later version. This is online at: *
14 * http://www.fsf.org/copyleft/gpl.html *
15 * Please send any updates to: fred@gruntose.com *
16 \*****************************************************************************/
18 /*! @file logging_macros.h
19 these macros can assist in logging. they rely on the base_logger class and the program-wide
20 logger class for logging services. note that it is often convenient to customize one or more
21 of these to yield a simpler macro name per project, such as PRINT or LOG.
24 #include <basis/enhance_cpp.h>
25 #include <loggers/logging_filters.h>
26 #include <timely/time_stamp.h>
28 ///hmmm: very temporary until the call stack tracking is available again.
29 #define update_current_stack_frame_line_number(x)
31 //! Logs a string "to_log" on "the_logger" using the "filter".
32 /*! The filter is checked before the string is allowed to come into
33 existence, which saves allocations when the item would never be printed
35 #define FILTER_LOG(the_logger, to_log, filter) { \
36 if (the_logger.member(filter)) { \
37 the_logger.log(to_log, filter); \
41 //! Logs a string at the emergency level, meaning that it always gets logged.
42 #define EMERGENCY_LOG(the_logger, to_log) \
43 FILTER_LOG(the_logger, to_log, basis::ALWAYS_PRINT)
45 //! Corresponding functions for including the time and date in the log entry.
46 #define STAMPED_FILTER_LOG(the_logger, to_log, filter) { \
47 if (the_logger.member(filter)) { \
48 astring temp_log = to_log; \
49 if (temp_log.length()) \
50 temp_log.insert(0, timely::time_stamp::notarize(true)); \
51 the_logger.log(temp_log, filter); \
54 //! Time-stamped logging that will always be printed.
55 #define STAMPED_EMERGENCY_LOG(the_logger, to_log) \
56 STAMPED_FILTER_LOG(the_logger, to_log, basis::ALWAYS_PRINT)
58 //! Class specific logging method that uses a filter.
59 /* These add a class and function name to the log entry. */
60 #define CLASS_FILTER_LOG(the_logger, to_log, filter) { \
61 update_current_stack_frame_line_number(__LINE__); \
62 if (the_logger.member(filter)) { \
63 astring temp_log = to_log; \
64 if (temp_log.length()) { \
65 temp_log.insert(0, timely::time_stamp::notarize(true)); \
66 BASE_FUNCTION(func); \
68 temp_log += function_name; \
71 the_logger.log(temp_log, filter); \
73 update_current_stack_frame_line_number(__LINE__); \
75 //! Class specific logging method that always prints.
76 #define CLASS_EMERGENCY_LOG(the_logger, to_log) \
77 CLASS_FILTER_LOG(the_logger, to_log, basis::ALWAYS_PRINT)
79 //! Logs information that includes specific class instance information.
80 /*! This use the instance name of the object, which can include more
81 information than the simple class name. */
82 #define INSTANCE_FILTER_LOG(the_logger, to_log, filter) { \
83 update_current_stack_frame_line_number(__LINE__); \
84 if (the_logger.member(filter)) { \
85 astring temp_log = to_log; \
86 if (temp_log.length()) { \
87 temp_log.insert(0, timely::time_stamp::notarize(true)); \
88 BASE_INSTANCE_FUNCTION(func); \
90 temp_log += function_name; \
93 the_logger.log(temp_log, filter); \
94 update_current_stack_frame_line_number(__LINE__); \
97 //! Logs with class instance info, but this always prints.
98 #define INSTANCE_EMERGENCY_LOG(the_logger, to_log) \
99 INSTANCE_FILTER_LOG(the_logger, to_log, basis::ALWAYS_PRINT)