Fawkes API Fawkes Development Version
logger.h
1
2/***************************************************************************
3 * logger.h - Fawkes logging interface
4 *
5 * Created: Tue Jan 16 20:36:32 2007
6 * Copyright 2006-2007 Tim Niemueller [www.niemueller.de]
7 *
8 ****************************************************************************/
9
10/* This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version. A runtime exception applies to
14 * this software (see LICENSE.GPL_WRE file mentioned below for details).
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Library General Public License for more details.
20 *
21 * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22 */
23
24#ifndef _UTILS_LOGGING_LOGGER_H_
25#define _UTILS_LOGGING_LOGGER_H_
26
27#include <core/exception.h>
28#include <sys/time.h>
29
30#include <cstdarg>
31
32#if defined(FAWKES_NO_LOGGING_FORMAT_CHECK)
33# define FAKWES_LOGGING_FORMAT_CHECK(string, arguments)
34#else
35# define FAKWES_LOGGING_FORMAT_CHECK(string, arguments) \
36 __attribute__((__format__(printf, string, arguments)))
37#endif
38
39namespace fawkes {
40
41class Logger
42{
43public:
44 /** Log level.
45 * Defines a level that can be used to determine the amount of output to
46 * generate in loggers. The log levels are strictly ordered
47 * (debug < info < warn < error < none) so loggers shall implement a
48 * facility to set a minimum logging level. Messages below that minimum
49 * log level shall be omitted.
50 */
51 typedef enum {
52 LL_DEBUG = 0, /**< debug output, relevant only when tracking down problems */
53 LL_INFO = 1, /**< informational output about normal procedures */
54 LL_WARN = 2, /**< warning, should be investigated but software still functions,
55 * an example is that something was requested that is not
56 * available and thus it is more likely a user error */
57 LL_ERROR = 4, /**< error, may be recoverable (software still running) or not
58 * (software has to terminate). This shall be used if the error
59 * is a rare situation that should be investigated. */
60 LL_NONE = 8 /**< use this to disable log output */
62
64 virtual ~Logger();
65
66 virtual void set_loglevel(LogLevel level);
67 virtual LogLevel loglevel();
68
69 FAKWES_LOGGING_FORMAT_CHECK(4, 5)
70 virtual void log(LogLevel level, const char *component, const char *format, ...);
71 FAKWES_LOGGING_FORMAT_CHECK(3, 4)
72 virtual void log_debug(const char *component, const char *format, ...) = 0;
73 FAKWES_LOGGING_FORMAT_CHECK(3, 4)
74 virtual void log_info(const char *component, const char *format, ...) = 0;
75 FAKWES_LOGGING_FORMAT_CHECK(3, 4)
76 virtual void log_warn(const char *component, const char *format, ...) = 0;
77 FAKWES_LOGGING_FORMAT_CHECK(3, 4)
78 virtual void log_error(const char *component, const char *format, ...) = 0;
79
80 virtual void log(LogLevel level, const char *component, Exception &e);
81 virtual void log_debug(const char *component, Exception &e) = 0;
82 virtual void log_info(const char *component, Exception &e) = 0;
83 virtual void log_warn(const char *component, Exception &e) = 0;
84 virtual void log_error(const char *component, Exception &e) = 0;
85
86 virtual void vlog(LogLevel level, const char *component, const char *format, va_list va);
87 virtual void vlog_debug(const char *component, const char *format, va_list va) = 0;
88 virtual void vlog_info(const char *component, const char *format, va_list va) = 0;
89 virtual void vlog_warn(const char *component, const char *format, va_list va) = 0;
90 virtual void vlog_error(const char *component, const char *format, va_list va) = 0;
91
92 FAKWES_LOGGING_FORMAT_CHECK(5, 6)
93 virtual void
94 tlog(LogLevel level, struct timeval *t, const char *component, const char *format, ...);
95 FAKWES_LOGGING_FORMAT_CHECK(4, 5)
96 virtual void tlog_debug(struct timeval *t, const char *component, const char *format, ...) = 0;
97 FAKWES_LOGGING_FORMAT_CHECK(4, 5)
98 virtual void tlog_info(struct timeval *t, const char *component, const char *format, ...) = 0;
99 FAKWES_LOGGING_FORMAT_CHECK(4, 5)
100 virtual void tlog_warn(struct timeval *t, const char *component, const char *format, ...) = 0;
101 FAKWES_LOGGING_FORMAT_CHECK(4, 5)
102 virtual void tlog_error(struct timeval *t, const char *component, const char *format, ...) = 0;
103
104 virtual void tlog(LogLevel level, struct timeval *t, const char *component, Exception &e);
105 virtual void tlog_debug(struct timeval *t, const char *component, Exception &e) = 0;
106 virtual void tlog_info(struct timeval *t, const char *component, Exception &e) = 0;
107 virtual void tlog_warn(struct timeval *t, const char *component, Exception &e) = 0;
108 virtual void tlog_error(struct timeval *t, const char *component, Exception &e) = 0;
109
110 virtual void
111 vtlog(LogLevel level, struct timeval *t, const char *component, const char *format, va_list va);
112 virtual void
113 vtlog_debug(struct timeval *t, const char *component, const char *format, va_list va) = 0;
114 virtual void
115 vtlog_info(struct timeval *t, const char *component, const char *format, va_list va) = 0;
116 virtual void
117 vtlog_warn(struct timeval *t, const char *component, const char *format, va_list va) = 0;
118 virtual void
119 vtlog_error(struct timeval *t, const char *component, const char *format, va_list va) = 0;
120
121protected:
122 /** Minimum log level.
123 * A logger shall only log output with a level equal or above the given level,
124 * it shall ignore all other messages.
125 */
127};
128
129} // end namespace fawkes
130
131#endif
Base class for exceptions in Fawkes.
Definition: exception.h:36
Interface for logging.
Definition: logger.h:42
virtual void vlog_error(const char *component, const char *format, va_list va)=0
Log error message.
virtual void vtlog(LogLevel level, struct timeval *t, const char *component, const char *format, va_list va)
Log message for given log level and time.
Definition: logger.cpp:302
virtual void tlog(LogLevel level, struct timeval *t, const char *component, const char *format,...)
Log message of given log level and time.
Definition: logger.cpp:363
virtual void vtlog_info(struct timeval *t, const char *component, const char *format, va_list va)=0
Log informational message for specific time.
virtual void tlog_warn(struct timeval *t, const char *component, const char *format,...)=0
Log warning message for specific time.
virtual LogLevel loglevel()
Get log level.
Definition: logger.cpp:267
virtual void log_debug(const char *component, const char *format,...)=0
Log debug message.
virtual void tlog_error(struct timeval *t, const char *component, const char *format,...)=0
Log error message for specific time.
virtual void vtlog_warn(struct timeval *t, const char *component, const char *format, va_list va)=0
Log warning message for specific time.
virtual void vtlog_error(struct timeval *t, const char *component, const char *format, va_list va)=0
Log error message for specific time.
virtual ~Logger()
Virtual empty destructor.
Definition: logger.cpp:248
virtual void log_warn(const char *component, const char *format,...)=0
Log warning message.
Logger(LogLevel log_level=LL_DEBUG)
Constructor.
Definition: logger.cpp:242
virtual void tlog_debug(struct timeval *t, const char *component, const char *format,...)=0
Log debug message for specific time.
virtual void log(LogLevel level, const char *component, const char *format,...)
Log message of given log level.
Definition: logger.cpp:326
virtual void log_error(const char *component, const char *format,...)=0
Log error message.
virtual void vlog_debug(const char *component, const char *format, va_list va)=0
Log debug message.
virtual void vlog_info(const char *component, const char *format, va_list va)=0
Log informational message.
LogLevel
Log level.
Definition: logger.h:51
@ LL_INFO
informational output about normal procedures
Definition: logger.h:53
@ LL_WARN
warning, should be investigated but software still functions, an example is that something was reques...
Definition: logger.h:54
@ LL_NONE
use this to disable log output
Definition: logger.h:60
@ LL_ERROR
error, may be recoverable (software still running) or not (software has to terminate).
Definition: logger.h:57
@ LL_DEBUG
debug output, relevant only when tracking down problems
Definition: logger.h:52
virtual void vtlog_debug(struct timeval *t, const char *component, const char *format, va_list va)=0
Log debug message for specific time.
virtual void vlog_warn(const char *component, const char *format, va_list va)=0
Log warning message.
virtual void set_loglevel(LogLevel level)
Sets the log level.
Definition: logger.cpp:258
virtual void vlog(LogLevel level, const char *component, const char *format, va_list va)
Log message for given log level.
Definition: logger.cpp:280
virtual void log_info(const char *component, const char *format,...)=0
Log informational message.
LogLevel log_level
Minimum log level.
Definition: logger.h:126
virtual void tlog_info(struct timeval *t, const char *component, const char *format,...)=0
Log informational message for specific time.
Fawkes library namespace.