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 <cstdarg>
29 #include <sys/time.h>
30 
31 namespace fawkes {
32 
33 
34 class Logger
35 {
36  public:
37 
38  /** Log level.
39  * Defines a level that can be used to determine the amount of output to
40  * generate in loggers. The log levels are strictly ordered
41  * (debug < info < warn < error < none) so loggers shall implement a
42  * facility to set a minimum logging level. Messages below that minimum
43  * log level shall be omitted.
44  */
45  typedef enum {
46  LL_DEBUG = 0, /**< debug output, relevant only when tracking down problems */
47  LL_INFO = 1, /**< informational output about normal procedures */
48  LL_WARN = 2, /**< warning, should be investigated but software still functions,
49  * an example is that something was requested that is not
50  * available and thus it is more likely a user error */
51  LL_ERROR = 4, /**< error, may be recoverable (software still running) or not
52  * (software has to terminate). This shall be used if the error
53  * is a rare situation that should be investigated. */
54  LL_NONE = 8 /**< use this to disable log output */
55  } LogLevel;
56 
58  virtual ~Logger();
59 
60  virtual void set_loglevel(LogLevel level);
61  virtual LogLevel loglevel();
62 
63  virtual void log(LogLevel level,
64  const char *component, const char *format, ...);
65  virtual void log_debug(const char *component, const char *format, ...) = 0;
66  virtual void log_info(const char *component, const char *format, ...) = 0;
67  virtual void log_warn(const char *component, const char *format, ...) = 0;
68  virtual void log_error(const char *component, const char *format, ...) = 0;
69 
70 
71  virtual void log(LogLevel level, const char *component, Exception &e);
72  virtual void log_debug(const char *component, Exception &e) = 0;
73  virtual void log_info(const char *component, Exception &e) = 0;
74  virtual void log_warn(const char *component, Exception &e) = 0;
75  virtual void log_error(const char *component, Exception &e) = 0;
76 
77  virtual void vlog(LogLevel level, const char *component,
78  const char *format, va_list va);
79  virtual void vlog_debug(const char *component,
80  const char *format, va_list va) = 0;
81  virtual void vlog_info(const char *component,
82  const char *format, va_list va) = 0;
83  virtual void vlog_warn(const char *component,
84  const char *format, va_list va) = 0;
85  virtual void vlog_error(const char *component,
86  const char *format, va_list va) = 0;
87 
88 
89  virtual void tlog(LogLevel level, struct timeval *t,
90  const char *component, const char *format, ...);
91  virtual void tlog_debug(struct timeval *t, const char *component,
92  const char *format, ...) = 0;
93  virtual void tlog_info(struct timeval *t, const char *component,
94  const char *format, ...) = 0;
95  virtual void tlog_warn(struct timeval *t, const char *component,
96  const char *format, ...) = 0;
97  virtual void tlog_error(struct timeval *t, const char *component,
98  const char *format, ...) = 0;
99 
100  virtual void tlog(LogLevel level, struct timeval *t, const char *component,
101  Exception &e);
102  virtual void tlog_debug(struct timeval *t, const char *component,
103  Exception &e) = 0;
104  virtual void tlog_info(struct timeval *t, const char *component,
105  Exception &e) = 0;
106  virtual void tlog_warn(struct timeval *t, const char *component,
107  Exception &e) = 0;
108  virtual void tlog_error(struct timeval *t, const char *component,
109  Exception &e) = 0;
110 
111  virtual void vtlog(LogLevel level, struct timeval *t, const char *component,
112  const char *format, va_list va);
113  virtual void vtlog_debug(struct timeval *t, const char *component,
114  const char *format, va_list va) = 0;
115  virtual void vtlog_info(struct timeval *t, const char *component,
116  const char *format, va_list va) = 0;
117  virtual void vtlog_warn(struct timeval *t, const char *component,
118  const char *format, va_list va) = 0;
119  virtual void vtlog_error(struct timeval *t, const char *component,
120  const char *format, va_list va) = 0;
121 
122 
123  protected:
124  /** Minimum log level.
125  * A logger shall only log output with a level equal or above the given level,
126  * it shall ignore all other messages.
127  */
129 };
130 
131 
132 } // end namespace fawkes
133 
134 #endif
LogLevel
Log level.
Definition: logger.h:45
virtual void tlog_error(struct timeval *t, const char *component, const char *format,...)=0
Log error message for specific time.
virtual void tlog_info(struct timeval *t, const char *component, const char *format,...)=0
Log informational message for specific time.
virtual void vlog_warn(const char *component, const char *format, va_list va)=0
Log warning message.
virtual void vtlog_warn(struct timeval *t, const char *component, const char *format, va_list va)=0
Log warning message for specific time.
LogLevel log_level
Minimum log level.
Definition: logger.h:128
informational output about normal procedures
Definition: logger.h:47
virtual void log_info(const char *component, const char *format,...)=0
Log informational message.
virtual void vlog_debug(const char *component, const char *format, va_list va)=0
Log debug message.
Fawkes library namespace.
warning, should be investigated but software still functions, an example is that something was reques...
Definition: logger.h:48
virtual void vlog_error(const char *component, const char *format, va_list va)=0
Log error message.
error, may be recoverable (software still running) or not (software has to terminate).
Definition: logger.h:51
virtual ~Logger()
Virtual empty destructor.
Definition: logger.cpp:233
virtual void tlog_debug(struct timeval *t, const char *component, const char *format,...)=0
Log debug message for specific time.
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:293
Base class for exceptions in Fawkes.
Definition: exception.h:36
virtual void vlog_info(const char *component, const char *format, va_list va)=0
Log informational message.
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(LogLevel level, const char *component, const char *format, va_list va)
Log message for given log level.
Definition: logger.cpp:268
Logger(LogLevel log_level=LL_DEBUG)
Constructor.
Definition: logger.cpp:226
virtual void log_warn(const char *component, const char *format,...)=0
Log warning message.
virtual void log_error(const char *component, const char *format,...)=0
Log error message.
debug output, relevant only when tracking down problems
Definition: logger.h:46
virtual void tlog_warn(struct timeval *t, const char *component, const char *format,...)=0
Log warning message for specific time.
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 log_debug(const char *component, const char *format,...)=0
Log debug message.
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:355
virtual LogLevel loglevel()
Get log level.
Definition: logger.cpp:254
virtual void log(LogLevel level, const char *component, const char *format,...)
Log message of given log level.
Definition: logger.cpp:315
virtual void vtlog_error(struct timeval *t, const char *component, const char *format, va_list va)=0
Log error message for specific time.
use this to disable log output
Definition: logger.h:54
Interface for logging.
Definition: logger.h:34
virtual void set_loglevel(LogLevel level)
Sets the log level.
Definition: logger.cpp:244