Appender.cpp
Go to the documentation of this file.
1 /*
2  * Appender.cpp
3  *
4  * Copyright 2000, LifeLine Networks BV (www.lifeline.nl). All rights reserved.
5  * Copyright 2000, Bastiaan Bakker. All rights reserved.
6  *
7  * See the COPYING file for the terms of usage and distribution.
8  */
9 
10 #include "PortabilityImpl.hh"
11 #include <log4cpp/Appender.hh>
12 
13 namespace log4cpp {
16 
17  /* assume _appenderMapMutex locked */
19  if (!_allAppenders)
21 
22  return *_allAppenders;
23  }
24 
25  Appender* Appender::getAppender(const std::string& name) {
27  AppenderMap& allAppenders = Appender::_getAllAppenders();
28  AppenderMap::iterator i = allAppenders.find(name);
29  return (allAppenders.end() == i) ? NULL : ((*i).second);
30  }
31 
32  void Appender::_addAppender(Appender* appender) {
33  //REQUIRE(_allAppenders.find(appender->getName()) == _getAllAppenders().end())
35  _getAllAppenders()[appender->getName()] = appender;
36  }
37 
40  _getAllAppenders().erase(appender->getName());
41  if(_getAllAppenders().size() == 0) {
42  delete _allAppenders; _allAppenders = 0; // fix for #2940452
43  }
44  }
45 
48  bool result = true;
49  AppenderMap& allAppenders = _getAllAppenders();
50  for(AppenderMap::iterator i = allAppenders.begin(); i != allAppenders.end(); i++) {
51  result = result && ((*i).second)->reopen();
52  }
53 
54  return result;
55  }
56 
59  AppenderMap& allAppenders = _getAllAppenders();
60  for(AppenderMap::iterator i = allAppenders.begin(); i != allAppenders.end(); i++) {
61  ((*i).second)->close();
62  }
63  }
64 
67  AppenderMap& allAppenders = _getAllAppenders();
68  for(AppenderMap::iterator i = allAppenders.begin(); i != allAppenders.end(); ) {
69  Appender *app = (*i).second;
70  i++; // increment iterator before delete or iterator will be invalid.
71  delete (app);
72  }
73  }
74 
75  Appender::Appender(const std::string& name) :
76  _name(name) {
77  _addAppender(this);
78  }
79 
81  _removeAppender(this);
82  }
83 }
static void _addAppender(Appender *appender)
Definition: Appender.cpp:32
static void closeAll()
Definition: Appender.cpp:57
virtual void close()=0
static threading::Mutex _appenderMapMutex
Definition: Appender.hh:137
static AppenderMap & _getAllAppenders()
Definition: Appender.cpp:18
static void _deleteAllAppenders()
Definition: Appender.cpp:65
static bool reopenAll()
Definition: Appender.cpp:46
const std::string _name
Definition: Appender.hh:144
virtual bool reopen()=0
Appender(const std::string &name)
Definition: Appender.cpp:75
boost::mutex Mutex
Definition: BoostThreads.hh:37
virtual ~Appender()
Definition: Appender.cpp:80
static void _removeAppender(Appender *appender)
Definition: Appender.cpp:38
static AppenderMap * _allAppenders
Definition: Appender.hh:136
std::map< std::string, Appender * > AppenderMap
Definition: Appender.hh:134
const std::string & getName() const
Definition: Appender.hh:106
static Appender * getAppender(const std::string &name)
Definition: Appender.cpp:25


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