00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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
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
00081 typedef struct {
00082 LogLevel log_level;
00083 std::string component;
00084 struct timeval time;
00085 std::string timestr;
00086 std::string message;
00087 } CacheEntry;
00088
00089
00090
00091
00092 std::list<CacheEntry> & get_messages();
00093
00094
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 }
00125
00126 #endif