Fawkes API
Fawkes Development Version
|
00001 00002 /*************************************************************************** 00003 * logger.h - Fawkes logging interface 00004 * 00005 * Created: Tue Jan 16 20:36:32 2007 00006 * Copyright 2006-2007 Tim Niemueller [www.niemueller.de] 00007 * 00008 ****************************************************************************/ 00009 00010 /* This program is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. A runtime exception applies to 00014 * this software (see LICENSE.GPL_WRE file mentioned below for details). 00015 * 00016 * This program is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU Library General Public License for more details. 00020 * 00021 * Read the full text in the LICENSE.GPL_WRE file in the doc directory. 00022 */ 00023 00024 #ifndef __UTILS_LOGGING_LOGGER_H_ 00025 #define __UTILS_LOGGING_LOGGER_H_ 00026 00027 #include <core/exception.h> 00028 #include <cstdarg> 00029 #include <sys/time.h> 00030 00031 namespace fawkes { 00032 00033 00034 class Logger 00035 { 00036 public: 00037 00038 /** Log level. 00039 * Defines a level that can be used to determine the amount of output to 00040 * generate in loggers. The log levels are strictly ordered 00041 * (debug < info < warn < error < none) so loggers shall implement a 00042 * facility to set a minimum logging level. Messages below that minimum 00043 * log level shall be omitted. 00044 */ 00045 typedef enum { 00046 LL_DEBUG = 0, /**< debug output, relevant only when tracking down problems */ 00047 LL_INFO = 1, /**< informational output about normal procedures */ 00048 LL_WARN = 2, /**< warning, should be investigated but software still functions, 00049 * an example is that something was requested that is not 00050 * available and thus it is more likely a user error */ 00051 LL_ERROR = 4, /**< error, may be recoverable (software still running) or not 00052 * (software has to terminate). This shall be used if the error 00053 * is a rare situation that should be investigated. */ 00054 LL_NONE = 8 /**< use this to disable log output */ 00055 } LogLevel; 00056 00057 Logger(LogLevel log_level = LL_DEBUG); 00058 virtual ~Logger(); 00059 00060 virtual void set_loglevel(LogLevel level); 00061 virtual LogLevel loglevel(); 00062 00063 virtual void log(LogLevel level, 00064 const char *component, const char *format, ...); 00065 virtual void log_debug(const char *component, const char *format, ...) = 0; 00066 virtual void log_info(const char *component, const char *format, ...) = 0; 00067 virtual void log_warn(const char *component, const char *format, ...) = 0; 00068 virtual void log_error(const char *component, const char *format, ...) = 0; 00069 00070 00071 virtual void log(LogLevel level, const char *component, Exception &e); 00072 virtual void log_debug(const char *component, Exception &e) = 0; 00073 virtual void log_info(const char *component, Exception &e) = 0; 00074 virtual void log_warn(const char *component, Exception &e) = 0; 00075 virtual void log_error(const char *component, Exception &e) = 0; 00076 00077 virtual void vlog(LogLevel level, const char *component, 00078 const char *format, va_list va); 00079 virtual void vlog_debug(const char *component, 00080 const char *format, va_list va) = 0; 00081 virtual void vlog_info(const char *component, 00082 const char *format, va_list va) = 0; 00083 virtual void vlog_warn(const char *component, 00084 const char *format, va_list va) = 0; 00085 virtual void vlog_error(const char *component, 00086 const char *format, va_list va) = 0; 00087 00088 00089 virtual void tlog(LogLevel level, struct timeval *t, 00090 const char *component, const char *format, ...); 00091 virtual void tlog_debug(struct timeval *t, const char *component, 00092 const char *format, ...) = 0; 00093 virtual void tlog_info(struct timeval *t, const char *component, 00094 const char *format, ...) = 0; 00095 virtual void tlog_warn(struct timeval *t, const char *component, 00096 const char *format, ...) = 0; 00097 virtual void tlog_error(struct timeval *t, const char *component, 00098 const char *format, ...) = 0; 00099 00100 virtual void tlog(LogLevel level, struct timeval *t, const char *component, 00101 Exception &e); 00102 virtual void tlog_debug(struct timeval *t, const char *component, 00103 Exception &e) = 0; 00104 virtual void tlog_info(struct timeval *t, const char *component, 00105 Exception &e) = 0; 00106 virtual void tlog_warn(struct timeval *t, const char *component, 00107 Exception &e) = 0; 00108 virtual void tlog_error(struct timeval *t, const char *component, 00109 Exception &e) = 0; 00110 00111 virtual void vtlog(LogLevel level, struct timeval *t, const char *component, 00112 const char *format, va_list va); 00113 virtual void vtlog_debug(struct timeval *t, const char *component, 00114 const char *format, va_list va) = 0; 00115 virtual void vtlog_info(struct timeval *t, const char *component, 00116 const char *format, va_list va) = 0; 00117 virtual void vtlog_warn(struct timeval *t, const char *component, 00118 const char *format, va_list va) = 0; 00119 virtual void vtlog_error(struct timeval *t, const char *component, 00120 const char *format, va_list va) = 0; 00121 00122 00123 protected: 00124 /** Minimum log level. 00125 * A logger shall only log output with a level equal or above the given level, 00126 * it shall ignore all other messages. 00127 */ 00128 LogLevel log_level; 00129 }; 00130 00131 00132 } // end namespace fawkes 00133 00134 #endif