-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBufferingAppender.cpp
More file actions
53 lines (44 loc) · 1.4 KB
/
BufferingAppender.cpp
File metadata and controls
53 lines (44 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
* Copyright 2002, Log4cpp Project. All rights reserved.
*
* See the COPYING file for the terms of usage and distribution.
*/
#include "PortabilityImpl.hh"
#include <log4cpp/BufferingAppender.hh>
#include <algorithm>
#include <sstream>
#include <memory>
namespace log4cpp
{
BufferingAppender::BufferingAppender(const std::string name, unsigned long max_size,
std::auto_ptr<Appender> sink, std::auto_ptr<TriggeringEventEvaluator> evaluator)
:LayoutAppender(name), max_size_(max_size), sink_(sink), evaluator_(evaluator), lossy_(false)
{
max_size_ = (max)(1UL, max_size_);
}
void BufferingAppender::_append(const LoggingEvent& event)
{
if (queue_.size() == max_size_)
if (lossy_)
queue_.pop_back();
else
dump();
queue_.push_front(event);
if (evaluator_->eval(event))
{
dump();
queue_.clear();
}
}
static const std::string EMPTY;
void BufferingAppender::dump()
{
Layout& layout = _getLayout();
std::ostringstream s;
// Solaris 10 CC can't work with const_reverse_iterator
for(queue_t::reverse_iterator i = queue_.rbegin(), last = queue_.rend(); i != last; ++i)
s << layout.format(*i);
LoggingEvent event(EMPTY, s.str(), EMPTY, Priority::NOTSET);
sink_->doAppend(event);
}
}