Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
src
BufferingAppender.cpp
Go to the documentation of this file.
1
/*
2
* Copyright 2002, Log4cpp Project. All rights reserved.
3
*
4
* See the COPYING file for the terms of usage and distribution.
5
*/
6
7
#include "
PortabilityImpl.hh
"
8
#include <
log4cpp/BufferingAppender.hh
>
9
#include <algorithm>
10
#include <sstream>
11
#include <memory>
12
13
namespace
log4cpp
14
{
15
BufferingAppender::BufferingAppender
(
const
std::string name,
unsigned
long
max_size,
16
std::auto_ptr<Appender> sink, std::auto_ptr<TriggeringEventEvaluator> evaluator)
17
:
LayoutAppender
(name), max_size_(max_size), sink_(sink), evaluator_(evaluator), lossy_(false)
18
{
19
max_size_
= (
max
)(1UL,
max_size_
);
20
}
21
22
void
BufferingAppender::_append
(
const
LoggingEvent
& event)
23
{
24
if
(
queue_
.size() ==
max_size_
)
25
{
26
if
(
lossy_
)
27
queue_
.pop_back();
28
else
29
dump
();
30
}
31
32
queue_
.push_front(event);
33
34
if
(
evaluator_
->eval(event))
35
{
36
dump
();
37
queue_
.clear();
38
}
39
}
40
41
static
const
std::string
EMPTY
;
42
43
void
BufferingAppender::dump
()
44
{
45
Layout
& layout =
_getLayout
();
46
std::ostringstream
s;
47
// Solaris 10 CC can't work with const_reverse_iterator
48
for
(queue_t::reverse_iterator i =
queue_
.rbegin(), last =
queue_
.rend(); i != last; ++i)
49
s << layout.
format
(*i);
50
51
LoggingEvent
event(EMPTY, s.
str
(),
EMPTY
,
Priority::NOTSET
);
52
sink_
->doAppend(event);
53
}
54
}
55
log4cpp::BufferingAppender::max_size_
unsigned long max_size_
Definition:
BufferingAppender.hh:36
PortabilityImpl.hh
log4cpp::BufferingAppender::dump
void dump()
Definition:
BufferingAppender.cpp:43
std::ostringstream::str
std::string str()
Definition:
PortabilityImpl.cpp:19
log4cpp::Layout
Definition:
Layout.hh:22
log4cpp::max
const T & max(const T &a, const T &b)
Definition:
PortabilityImpl.hh:64
log4cpp::Priority::NOTSET
Definition:
Priority.hh:79
log4cpp::BufferingAppender::_append
virtual void _append(const LoggingEvent &event)
Definition:
BufferingAppender.cpp:22
log4cpp::LayoutAppender::_getLayout
Layout & _getLayout()
Definition:
LayoutAppender.cpp:36
log4cpp
Definition:
AbortAppender.hh:16
BufferingAppender.hh
log4cpp::BufferingAppender::queue_
queue_t queue_
Definition:
BufferingAppender.hh:35
log4cpp::LoggingEvent
Definition:
LoggingEvent.hh:32
log4cpp::BufferingAppender::BufferingAppender
BufferingAppender(const std::string name, unsigned long max_size, std::auto_ptr< Appender > sink, std::auto_ptr< TriggeringEventEvaluator > evaluator)
Definition:
BufferingAppender.cpp:15
log4cpp::BufferingAppender::evaluator_
std::auto_ptr< TriggeringEventEvaluator > evaluator_
Definition:
BufferingAppender.hh:38
std::ostringstream
Definition:
Portability.hh:45
log4cpp::BufferingAppender::sink_
std::auto_ptr< Appender > sink_
Definition:
BufferingAppender.hh:37
log4cpp::EMPTY
static const std::string EMPTY
Definition:
BufferingAppender.cpp:41
log4cpp::LayoutAppender
Definition:
LayoutAppender.hh:24
log4cpp::Layout::format
virtual std::string format(const LoggingEvent &event)=0
log4cpp::BufferingAppender::lossy_
bool lossy_
Definition:
BufferingAppender.hh:39
log4cpp
Author(s): Stephen Roderick, Bastiaan Bakker, Cedric Le Goater, Steve Ostlind, Marcel Harkema, Walter Stroebel, Glenn Scott and Tony Cheung
autogenerated on Sun Jun 23 2019 19:14:17