Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
src
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
{
14
Appender::AppenderMap
*
Appender::_allAppenders
= 0;
15
threading::Mutex
Appender::_appenderMapMutex
;
16
17
/* assume _appenderMapMutex locked */
18
Appender::AppenderMap
&
Appender::_getAllAppenders
() {
19
if
(!
_allAppenders
)
20
_allAppenders
=
new
Appender::AppenderMap
();
21
22
return
*
_allAppenders
;
23
}
24
25
Appender
*
Appender::getAppender
(
const
std::string& name) {
26
threading::ScopedLock
lock(
_appenderMapMutex
);
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())
34
threading::ScopedLock
lock(
_appenderMapMutex
);
35
_getAllAppenders
()[appender->
getName
()] = appender;
36
}
37
38
void
Appender::_removeAppender
(
Appender
* appender) {
39
threading::ScopedLock
lock(
_appenderMapMutex
);
40
_getAllAppenders
().erase(appender->
getName
());
41
if
(
_getAllAppenders
().size() == 0) {
42
delete
_allAppenders
;
_allAppenders
= 0;
// fix for #2940452
43
}
44
}
45
46
bool
Appender::reopenAll
() {
47
threading::ScopedLock
lock(
_appenderMapMutex
);
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
57
void
Appender::closeAll
() {
58
threading::ScopedLock
lock(
_appenderMapMutex
);
59
AppenderMap
& allAppenders =
_getAllAppenders
();
60
for
(AppenderMap::iterator i = allAppenders.begin(); i != allAppenders.end(); i++) {
61
((*i).second)->
close
();
62
}
63
}
64
65
void
Appender::_deleteAllAppenders
() {
66
threading::ScopedLock
lock(
_appenderMapMutex
);
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
80
Appender::~Appender
() {
81
_removeAppender
(
this
);
82
}
83
}
log4cpp::Appender::_addAppender
static void _addAppender(Appender *appender)
Definition:
Appender.cpp:32
log4cpp::Appender::closeAll
static void closeAll()
Definition:
Appender.cpp:57
log4cpp::Appender::close
virtual void close()=0
log4cpp::Appender::_appenderMapMutex
static threading::Mutex _appenderMapMutex
Definition:
Appender.hh:137
PortabilityImpl.hh
log4cpp::threading::ScopedLock
Definition:
PThreads.hh:65
log4cpp::Appender::_getAllAppenders
static AppenderMap & _getAllAppenders()
Definition:
Appender.cpp:18
log4cpp::Appender::_deleteAllAppenders
static void _deleteAllAppenders()
Definition:
Appender.cpp:65
log4cpp::Appender::reopenAll
static bool reopenAll()
Definition:
Appender.cpp:46
Appender.hh
log4cpp::Appender::_name
const std::string _name
Definition:
Appender.hh:144
log4cpp::Appender::reopen
virtual bool reopen()=0
log4cpp::Appender::Appender
Appender(const std::string &name)
Definition:
Appender.cpp:75
log4cpp
Definition:
AbortAppender.hh:16
log4cpp::threading::Mutex
boost::mutex Mutex
Definition:
BoostThreads.hh:37
log4cpp::Appender::~Appender
virtual ~Appender()
Definition:
Appender.cpp:80
log4cpp::Appender::_removeAppender
static void _removeAppender(Appender *appender)
Definition:
Appender.cpp:38
log4cpp::Appender
Definition:
Appender.hh:33
log4cpp::Appender::_allAppenders
static AppenderMap * _allAppenders
Definition:
Appender.hh:136
log4cpp::Appender::AppenderMap
std::map< std::string, Appender * > AppenderMap
Definition:
Appender.hh:134
log4cpp::Appender::getName
const std::string & getName() const
Definition:
Appender.hh:106
log4cpp::Appender::getAppender
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:14:17