first check-in of feisty meow codebase. many things broken still due to recent
[feisty_meow.git] / core / library / loggers / logging_macros.h
1 #ifndef LOGGING_MACROS_GROUP
2 #define LOGGING_MACROS_GROUP
3
4 /*****************************************************************************\
5 *                                                                             *
6 *  Name   : logging macros                                                    *
7 *  Author : Chris Koeritz                                                     *
8 *                                                                             *
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 \*****************************************************************************/
17
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.
22 */
23
24 #include <basis/enhance_cpp.h>
25 #include <loggers/logging_filters.h>
26 #include <timely/time_stamp.h>
27
28 ///hmmm: very temporary until the call stack tracking is available again.
29 #define update_current_stack_frame_line_number(x)
30
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
34 out anyway. */
35 #define FILTER_LOG(the_logger, to_log, filter) { \
36   if (the_logger.member(filter)) { \
37     the_logger.log(to_log, filter); \
38   } \
39 }
40
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)
44
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); \
52   } \
53 }
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)
57
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); \
67       temp_log += " ["; \
68       temp_log += function_name; \
69       temp_log += "]"; \
70     } \
71     the_logger.log(temp_log, filter); \
72   } \
73   update_current_stack_frame_line_number(__LINE__); \
74 }
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)
78
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); \
89       temp_log += " ["; \
90       temp_log += function_name; \
91       temp_log += "]"; \
92     } \
93     the_logger.log(temp_log, filter); \
94     update_current_stack_frame_line_number(__LINE__); \
95   } \
96 }
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)
100
101 #endif
102