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 
39 namespace fawkes {
40 
41 class Logger
42 {
43 public:
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 */
61  } LogLevel;
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 
121 protected:
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
fawkes::Logger::log
virtual void log(LogLevel level, const char *component, const char *format,...)
Log message of given log level.
Definition: logger.cpp:325
fawkes::Logger::set_loglevel
virtual void set_loglevel(LogLevel level)
Sets the log level.
Definition: logger.cpp:257
fawkes::Logger::vlog_debug
virtual void vlog_debug(const char *component, const char *format, va_list va)=0
fawkes::Logger::log_level
LogLevel log_level
Minimum log level.
Definition: logger.h:125
fawkes::Logger::vtlog
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:301
fawkes::Logger::tlog_warn
virtual void tlog_warn(struct timeval *t, const char *component, const char *format,...)=0
fawkes::Logger::tlog_error
virtual void tlog_error(struct timeval *t, const char *component, const char *format,...)=0
fawkes::Logger::log_info
virtual void log_info(const char *component, const char *format,...)=0
fawkes::Logger::vlog_warn
virtual void vlog_warn(const char *component, const char *format, va_list va)=0
fawkes::Logger::~Logger
virtual ~Logger()
Virtual empty destructor.
Definition: logger.cpp:247
fawkes::Logger::LL_DEBUG
debug output, relevant only when tracking down problems
Definition: logger.h:51
fawkes::Logger::vtlog_info
virtual void vtlog_info(struct timeval *t, const char *component, const char *format, va_list va)=0
fawkes::Logger::vtlog_error
virtual void vtlog_error(struct timeval *t, const char *component, const char *format, va_list va)=0
fawkes::Logger::log_error
virtual void log_error(const char *component, const char *format,...)=0
fawkes::Logger::LL_INFO
informational output about normal procedures
Definition: logger.h:52
fawkes::Logger
Definition: logger.h:40
fawkes
fawkes::Logger::tlog_info
virtual void tlog_info(struct timeval *t, const char *component, const char *format,...)=0
fawkes::Logger::LL_ERROR
error, may be recoverable (software still running) or not (software has to terminate).
Definition: logger.h:56
fawkes::Logger::log_warn
virtual void log_warn(const char *component, const char *format,...)=0
fawkes::Logger::tlog_debug
virtual void tlog_debug(struct timeval *t, const char *component, const char *format,...)=0
fawkes::Logger::vtlog_debug
virtual void vtlog_debug(struct timeval *t, const char *component, const char *format, va_list va)=0
fawkes::Logger::vtlog_warn
virtual void vtlog_warn(struct timeval *t, const char *component, const char *format, va_list va)=0
fawkes::Logger::loglevel
virtual LogLevel loglevel()
Get log level.
Definition: logger.cpp:266
fawkes::Logger::LogLevel
LogLevel
Log level.
Definition: logger.h:50
fawkes::Logger::vlog_error
virtual void vlog_error(const char *component, const char *format, va_list va)=0
fawkes::Logger::Logger
Logger(LogLevel log_level=LL_DEBUG)
Constructor.
Definition: logger.cpp:241
fawkes::Logger::vlog_info
virtual void vlog_info(const char *component, const char *format, va_list va)=0
fawkes::Logger::LL_NONE
use this to disable log output
Definition: logger.h:59
fawkes::Logger::LL_WARN
warning, should be investigated but software still functions, an example is that something was reques...
Definition: logger.h:53
fawkes::Logger::tlog
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:362
fawkes::Logger::vlog
virtual void vlog(LogLevel level, const char *component, const char *format, va_list va)
Log message for given log level.
Definition: logger.cpp:279
fawkes::Logger::log_debug
virtual void log_debug(const char *component, const char *format,...)=0
fawkes::Exception
Definition: exception.h:39