Fawkes API Fawkes Development Version
cache.h
1
2/***************************************************************************
3 * cache.h - Fawkes cache logger
4 *
5 * Created: Wed Feb 11 22:54:23 2009
6 * Copyright 2006-2009 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_CACHE_H_
25#define _UTILS_LOGGING_CACHE_H_
26
27#include <logging/logger.h>
28
29#include <ctime>
30#include <list>
31#include <string>
32
33namespace fawkes {
34
35class Mutex;
36
37class CacheLogger : public Logger
38{
39public:
40 CacheLogger(unsigned int num_entries = 20, LogLevel log_level = LL_DEBUG);
41 virtual ~CacheLogger();
42
43 virtual void log_debug(const char *component, const char *format, ...);
44 virtual void log_info(const char *component, const char *format, ...);
45 virtual void log_warn(const char *component, const char *format, ...);
46 virtual void log_error(const char *component, const char *format, ...);
47
48 virtual void vlog_debug(const char *component, const char *format, va_list va);
49 virtual void vlog_info(const char *component, const char *format, va_list va);
50 virtual void vlog_warn(const char *component, const char *format, va_list va);
51 virtual void vlog_error(const char *component, const char *format, va_list va);
52
53 virtual void log_debug(const char *component, Exception &e);
54 virtual void log_info(const char *component, Exception &e);
55 virtual void log_warn(const char *component, Exception &e);
56 virtual void log_error(const char *component, Exception &e);
57
58 virtual void tlog_debug(struct timeval *t, const char *component, const char *format, ...);
59 virtual void tlog_info(struct timeval *t, const char *component, const char *format, ...);
60 virtual void tlog_warn(struct timeval *t, const char *component, const char *format, ...);
61 virtual void tlog_error(struct timeval *t, const char *component, const char *format, ...);
62
63 virtual void tlog_debug(struct timeval *t, const char *component, Exception &e);
64 virtual void tlog_info(struct timeval *t, const char *component, Exception &e);
65 virtual void tlog_warn(struct timeval *t, const char *component, Exception &e);
66 virtual void tlog_error(struct timeval *t, const char *component, Exception &e);
67
68 virtual void
69 vtlog_debug(struct timeval *t, const char *component, const char *format, va_list va);
70 virtual void vtlog_info(struct timeval *t, const char *component, const char *format, va_list va);
71 virtual void vtlog_warn(struct timeval *t, const char *component, const char *format, va_list va);
72 virtual void
73 vtlog_error(struct timeval *t, const char *component, const char *format, va_list va);
74
75 /** Cache entry struct. */
76 typedef struct
77 {
78 LogLevel log_level; /**< log level */
79 std::string component; /**< component */
80 struct timeval time; /**< raw time */
81 std::string timestr; /**< Time encoded as string */
82 std::string message; /**< Message */
83 } CacheEntry;
84
85 /** Get messages.
86 * @return reference to message list
87 */
88 std::list<CacheEntry> &get_messages();
89
90 /** Clear messages. */
91 void clear();
92
93 unsigned int size() const;
94 void set_size(unsigned int new_size);
95
96 void lock();
97 void unlock();
98
99private:
100 void push_message(LogLevel ll, const char *component, const char *format, va_list va);
101 void push_message(LogLevel ll, const char *component, Exception &e);
102 void tlog_push_message(LogLevel ll,
103 struct timeval *t,
104 const char * component,
105 const char * format,
106 va_list va);
107 void tlog_push_message(LogLevel ll, struct timeval *t, const char *component, Exception &);
108
109private:
110 struct ::tm *now_s;
111 Mutex * mutex;
112
113 std::list<CacheEntry> messages_;
114 unsigned int num_entries_;
115 unsigned int max_num_entries_;
116};
117
118} // end namespace fawkes
119
120#endif
Logging Cache.
Definition: cache.h:38
virtual void vtlog_error(struct timeval *t, const char *component, const char *format, va_list va)
Log error message for specific time.
Definition: cache.cpp:447
virtual void tlog_debug(struct timeval *t, const char *component, const char *format,...)
Log debug message for specific time.
Definition: cache.cpp:369
virtual void log_debug(const char *component, const char *format,...)
Log debug message.
Definition: cache.cpp:227
virtual void vtlog_debug(struct timeval *t, const char *component, const char *format, va_list va)
Log debug message for specific time.
Definition: cache.cpp:429
virtual void tlog_warn(struct timeval *t, const char *component, const char *format,...)
Log warning message for specific time.
Definition: cache.cpp:387
virtual void log_info(const char *component, const char *format,...)
Log informational message.
Definition: cache.cpp:236
std::list< CacheEntry > & get_messages()
Get messages.
Definition: cache.cpp:65
void clear()
Clear messages.
Definition: cache.cpp:71
unsigned int size() const
Get maximum number of log entries in cache.
Definition: cache.cpp:83
virtual void vtlog_info(struct timeval *t, const char *component, const char *format, va_list va)
Log informational message for specific time.
Definition: cache.cpp:435
virtual void vlog_error(const char *component, const char *format, va_list va)
Log error message.
Definition: cache.cpp:221
void lock()
Lock cache logger, no new messages can be added.
Definition: cache.cpp:106
virtual void log_warn(const char *component, const char *format,...)
Log warning message.
Definition: cache.cpp:245
void set_size(unsigned int new_size)
Set maximum number of log entries in cache.
Definition: cache.cpp:92
virtual void vlog_debug(const char *component, const char *format, va_list va)
Log debug message.
Definition: cache.cpp:203
void unlock()
Unlock cache logger.
Definition: cache.cpp:113
virtual void tlog_info(struct timeval *t, const char *component, const char *format,...)
Log informational message for specific time.
Definition: cache.cpp:378
CacheLogger(unsigned int num_entries=20, LogLevel log_level=LL_DEBUG)
Constructor.
Definition: cache.cpp:48
virtual void vlog_warn(const char *component, const char *format, va_list va)
Log warning message.
Definition: cache.cpp:215
virtual ~CacheLogger()
Destructor.
Definition: cache.cpp:58
virtual void log_error(const char *component, const char *format,...)
Log error message.
Definition: cache.cpp:254
virtual void vtlog_warn(struct timeval *t, const char *component, const char *format, va_list va)
Log warning message for specific time.
Definition: cache.cpp:441
virtual void vlog_info(const char *component, const char *format, va_list va)
Log informational message.
Definition: cache.cpp:209
virtual void tlog_error(struct timeval *t, const char *component, const char *format,...)
Log error message for specific time.
Definition: cache.cpp:396
Base class for exceptions in Fawkes.
Definition: exception.h:36
Interface for logging.
Definition: logger.h:42
LogLevel
Log level.
Definition: logger.h:51
@ LL_DEBUG
debug output, relevant only when tracking down problems
Definition: logger.h:52
LogLevel log_level
Minimum log level.
Definition: logger.h:126
Mutex mutual exclusion lock.
Definition: mutex.h:33
Fawkes library namespace.
Cache entry struct.
Definition: cache.h:77
std::string timestr
Time encoded as string.
Definition: cache.h:81
std::string component
component
Definition: cache.h:79
LogLevel log_level
log level
Definition: cache.h:78
std::string message
Message.
Definition: cache.h:82