Kea  1.9.9-git
buffer_appender_impl.h
Go to the documentation of this file.
1 // Copyright (C) 2012-2015 Internet Systems Consortium, Inc. ("ISC")
2 //
3 // This Source Code Form is subject to the terms of the Mozilla Public
4 // License, v. 2.0. If a copy of the MPL was not distributed with this
5 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 
7 #ifndef LOG_BUFFER_H
8 #define LOG_BUFFER_H
9 
10 #include <exceptions/exceptions.h>
11 
12 #include <log4cplus/logger.h>
13 #include <log4cplus/spi/loggingevent.h>
14 #include <boost/shared_ptr.hpp>
15 
16 namespace isc {
17 namespace log {
18 namespace internal {
19 
27 public:
28  LogBufferAddAfterFlush(const char* file, size_t line, const char* what) :
29  isc::Exception(file, line, what)
30  {}
31 };
32 
34 typedef boost::shared_ptr<log4cplus::spi::InternalLoggingEvent> LogEventPtr;
35 
39 typedef std::pair<std::string, LogEventPtr> LevelAndEvent;
40 
42 typedef std::vector<LevelAndEvent> LogEventList;
43 
65 class BufferAppender : public log4cplus::Appender {
66 public:
70  BufferAppender() : flushed_(false) {}
71 
76  virtual ~BufferAppender();
77 
81  virtual void close() {}
82 
88  void flush();
89 
93  size_t getBufferSize() const;
94 
95 protected:
96  virtual void append(const log4cplus::spi::InternalLoggingEvent& event);
97 private:
99  void flushStdout();
100 
101  LogEventList stored_;
102  bool flushed_;
103 };
104 
105 } // end namespace internal
106 } // end namespace log
107 } // end namespace isc
108 
109 #endif // LOG_BUFFER_H
110 
std::vector< LevelAndEvent > LogEventList
Convenience typedef for a vector of LevelAndEvent instances.
boost::shared_ptr< log4cplus::spi::InternalLoggingEvent > LogEventPtr
Convenience typedef for a pointer to a log event.
virtual void close()
Close the appender.
size_t getBufferSize() const
Returns the number of stored logging events.
LogBufferAddAfterFlush(const char *file, size_t line, const char *what)
virtual void append(const log4cplus::spi::InternalLoggingEvent &event)
std::pair< std::string, LogEventPtr > LevelAndEvent
Convenience typedef for a pair string/logeventptr, the string representing the logger level...
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
This is a base class for exceptions thrown from the DNS library module.
Defines the logger used by the top-level component of kea-dhcp-ddns.
void flush()
Flush the internal buffer.