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"
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 
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 
44  {
45  Layout& layout = _getLayout();
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 
const T & max(const T &a, const T &b)
virtual void _append(const LoggingEvent &event)
BufferingAppender(const std::string name, unsigned long max_size, std::auto_ptr< Appender > sink, std::auto_ptr< TriggeringEventEvaluator > evaluator)
std::auto_ptr< TriggeringEventEvaluator > evaluator_
std::auto_ptr< Appender > sink_
static const std::string EMPTY
virtual std::string format(const LoggingEvent &event)=0


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:10:00