4
* Copyright (C) 2010 Eric Day (eday@oddments.org)
7
* Use and distribution licensed under the BSD license. See the
8
* COPYING file in the root project directory for full text.
13
* @brief Kernel Logger Base Class
16
#ifndef SCALESTACK_KERNEL_LOGGER_H
17
#define SCALESTACK_KERNEL_LOGGER_H
21
#include <scalestack/common/exception.h>
22
#include <scalestack/kernel/log.h>
30
* Base class available for kernel classes that produce log messages.
32
class SCALESTACK_API logger
36
logger(size_t threshold);
41
* Set the threshold for logging messages.
43
* @param[in] threshold The new log threshold to set.
45
void set_threshold(size_t threshold);
48
* Log a fatal message with the formatted string if log threshold is met.
50
* @param[in] format Message format string.
52
void log_fatal(const char* format, ...) const;
55
* Log an error message with the formatted string if log threshold is met.
57
* @param[in] format Message format string.
59
void log_error(const char* format, ...) const;
62
* Log a notice message with the formatted string if log threshold is met.
64
* @param[in] format Message format string.
66
void log_notice(const char* format, ...) const;
69
* Log an info message with the formatted string if log threshold is met.
71
* @param[in] format Message format string.
73
void log_info(const char* format, ...) const;
76
* Log a debug message with the formatted string if log threshold is met.
78
* @param[in] format Message format string.
80
void log_debug(const char* format, ...) const;
89
* Don't allow copying of objects.
91
logger(const logger&);
94
* Don't allow assignment of objects.
96
logger& operator=(const logger&);
99
* Set a fatal error message. This is used so fatal messages can be caught
100
* for error strings even if logging threshold is not met.
102
* @param[in] format Message format string.
103
* @param[in] arguments Argument list for formatted message.
105
virtual void _set_fatal_message(const char* format,
106
std::va_list arguments) const = 0;
111
* @param[in] log_level Log level for this message.
112
* @param[in] format Message format string.
113
* @param[in] arguments Argument list for formatted message.
115
virtual void _log_message(log::level log_level,
117
std::va_list arguments) const = 0;
124
inline logger::logger(size_t threshold):
125
_threshold(threshold)
129
inline logger::~logger()
133
inline void logger::set_threshold(size_t threshold)
135
_threshold = threshold;
138
inline void logger::log_fatal(const char* format, ...) const
140
std::va_list arguments;
141
va_start(arguments, format);
144
* We know this is going to trigger a catch because fatal messages throw
145
* exceptions, so this is done so we can call va_end before passing on
151
_log_message(log::LEVEL_FATAL, format, arguments);
153
_set_fatal_message(format, arguments);
155
catch (common::exception&)
164
inline void logger::log_error(const char* format, ...) const
168
std::va_list arguments;
169
va_start(arguments, format);
170
_log_message(log::LEVEL_ERROR, format, arguments);
175
inline void logger::log_notice(const char* format, ...) const
179
std::va_list arguments;
180
va_start(arguments, format);
181
_log_message(log::LEVEL_NOTICE, format, arguments);
186
inline void logger::log_info(const char* format, ...) const
190
std::va_list arguments;
191
va_start(arguments, format);
192
_log_message(log::LEVEL_INFO, format, arguments);
197
inline void logger::log_debug(const char* format, ...) const
201
std::va_list arguments;
202
va_start(arguments, format);
203
_log_message(log::LEVEL_DEBUG, format, arguments);
208
} /* namespace kernel */
209
} /* namespace scalestack */
211
#endif /* SCALESTACK_KERNEL_LOGGER_H */