Fawkes API
Fawkes Development Version
|
00001 00002 /*************************************************************************** 00003 * cache.h - Fawkes cache logger 00004 * 00005 * Created: Wed Feb 11 22:54:23 2009 00006 * Copyright 2006-2009 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_CACHE_H_ 00025 #define __UTILS_LOGGING_CACHE_H_ 00026 00027 #include <utils/logging/logger.h> 00028 #include <ctime> 00029 00030 #include <string> 00031 #include <list> 00032 00033 namespace fawkes { 00034 #if 0 /* just to make Emacs auto-indent happy */ 00035 } 00036 #endif 00037 00038 class Mutex; 00039 00040 class CacheLogger : public Logger 00041 { 00042 public: 00043 CacheLogger(unsigned int num_entries = 20, LogLevel log_level = LL_DEBUG); 00044 virtual ~CacheLogger(); 00045 00046 virtual void log_debug(const char *component, const char *format, ...); 00047 virtual void log_info(const char *component, const char *format, ...); 00048 virtual void log_warn(const char *component, const char *format, ...); 00049 virtual void log_error(const char *component, const char *format, ...); 00050 00051 virtual void vlog_debug(const char *component, const char *format, va_list va); 00052 virtual void vlog_info(const char *component, const char *format, va_list va); 00053 virtual void vlog_warn(const char *component, const char *format, va_list va); 00054 virtual void vlog_error(const char *component, const char *format, va_list va); 00055 00056 virtual void log_debug(const char *component, Exception &e); 00057 virtual void log_info(const char *component, Exception &e); 00058 virtual void log_warn(const char *component, Exception &e); 00059 virtual void log_error(const char *component, Exception &e); 00060 00061 virtual void tlog_debug(struct timeval *t, const char *component, const char *format, ...); 00062 virtual void tlog_info(struct timeval *t, const char *component, const char *format, ...); 00063 virtual void tlog_warn(struct timeval *t, const char *component, const char *format, ...); 00064 virtual void tlog_error(struct timeval *t, const char *component, const char *format, ...); 00065 00066 virtual void tlog_debug(struct timeval *t, const char *component, Exception &e); 00067 virtual void tlog_info(struct timeval *t, const char *component, Exception &e); 00068 virtual void tlog_warn(struct timeval *t, const char *component, Exception &e); 00069 virtual void tlog_error(struct timeval *t, const char *component, Exception &e); 00070 00071 virtual void vtlog_debug(struct timeval *t, const char *component, 00072 const char *format, va_list va); 00073 virtual void vtlog_info(struct timeval *t, const char *component, 00074 const char *format, va_list va); 00075 virtual void vtlog_warn(struct timeval *t, const char *component, 00076 const char *format, va_list va); 00077 virtual void vtlog_error(struct timeval *t, const char *component, 00078 const char *format, va_list va); 00079 00080 /** Cache entry struct. */ 00081 typedef struct { 00082 LogLevel log_level; /**< log level */ 00083 std::string component; /**< component */ 00084 struct timeval time; /**< raw time */ 00085 std::string timestr; /**< Time encoded as string */ 00086 std::string message; /**< Message */ 00087 } CacheEntry; 00088 00089 /** Get messages. 00090 * @return reference to message list 00091 */ 00092 std::list<CacheEntry> & get_messages(); 00093 00094 /** Clear messages. */ 00095 void clear(); 00096 00097 unsigned int size() const; 00098 void set_size(unsigned int new_size); 00099 00100 void lock(); 00101 void unlock(); 00102 00103 private: 00104 void push_message(LogLevel ll, const char *component, const char *format, 00105 va_list va); 00106 void push_message(LogLevel ll, const char *component, Exception &e); 00107 void tlog_push_message(LogLevel ll, struct timeval *t, const char *component, 00108 const char *format, va_list va); 00109 void tlog_push_message(LogLevel ll, struct timeval *t, const char *component, 00110 Exception &); 00111 00112 00113 private: 00114 struct ::tm *now_s; 00115 Mutex *mutex; 00116 00117 std::list<CacheEntry> __messages; 00118 unsigned int __num_entries; 00119 unsigned int __max_num_entries; 00120 00121 }; 00122 00123 00124 } // end namespace fawkes 00125 00126 #endif