Kea  1.5.0
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 
isc::log::internal::LogEventPtr
boost::shared_ptr< log4cplus::spi::InternalLoggingEvent > LogEventPtr
Convenience typedef for a pointer to a log event.
Definition: buffer_appender_impl.h:34
isc::log::internal::LogBufferAddAfterFlush::LogBufferAddAfterFlush
LogBufferAddAfterFlush(const char *file, size_t line, const char *what)
Definition: buffer_appender_impl.h:28
isc::log::internal::BufferAppender
Buffering Logger Appender.
Definition: buffer_appender_impl.h:65
isc::log::internal::BufferAppender::append
virtual void append(const log4cplus::spi::InternalLoggingEvent &event)
Definition: buffer_appender_impl.cc:75
isc::Exception
This is a base class for exceptions thrown from the DNS library module.
Definition: exceptions/exceptions.h:23
isc
Defines the logger used by the top-level component of kea-dhcp-ddns.
Definition: agent_parser.cc:144
isc::Exception::what
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Definition: exceptions/exceptions.cc:32
isc::log::internal::BufferAppender::BufferAppender
BufferAppender()
Constructor.
Definition: buffer_appender_impl.h:70
isc::log::internal::LogEventList
std::vector< LevelAndEvent > LogEventList
Convenience typedef for a vector of LevelAndEvent instances.
Definition: buffer_appender_impl.h:42
isc::log::internal::BufferAppender::close
virtual void close()
Close the appender.
Definition: buffer_appender_impl.h:81
exceptions.h
isc::log::internal::LogBufferAddAfterFlush
Buffer add after flush.
Definition: buffer_appender_impl.h:26
isc::log::internal::BufferAppender::~BufferAppender
virtual ~BufferAppender()
Destructor.
Definition: buffer_appender_impl.cc:20
isc::log::internal::LevelAndEvent
std::pair< std::string, LogEventPtr > LevelAndEvent
Convenience typedef for a pair string/logeventptr, the string representing the logger level,...
Definition: buffer_appender_impl.h:39
isc::log::internal::BufferAppender::flush
void flush()
Flush the internal buffer.
Definition: buffer_appender_impl.cc:54
isc::log::internal::BufferAppender::getBufferSize
size_t getBufferSize() const
Returns the number of stored logging events.
Definition: buffer_appender_impl.cc:70