Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
src
NDC.cpp
Go to the documentation of this file.
1
/*
2
* NDC.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/NDC.hh
>
12
#include <
log4cpp/threading/Threading.hh
>
13
14
namespace
log4cpp
{
15
16
NDC::DiagnosticContext::DiagnosticContext
(
const
std::string& message) :
17
message(message),
18
fullMessage(message) {
19
}
20
21
NDC::DiagnosticContext::DiagnosticContext
(
const
std::string&
message
,
22
const
DiagnosticContext
& parent) :
23
message(message),
24
fullMessage
(parent.
fullMessage
+
" "
+ message) {
25
}
26
27
bool
NDC::isUsedNDC
=
false
;
28
const
std::string
NDC::emptyString
=
""
;
29
30
namespace
{
31
threading::ThreadLocalDataHolder<NDC>
_nDC;
32
}
33
34
void
NDC::clear
() {
35
getNDC
().
_clear
();
36
}
37
38
NDC::ContextStack
*
NDC::cloneStack
() {
39
return
getNDC
().
_cloneStack
();
40
}
41
42
const
std::string&
NDC::get
() {
43
if
(
isUsedNDC
)
44
return
getNDC
().
_get
();
45
else
46
return
emptyString
;
47
}
48
49
size_t
NDC::getDepth
() {
50
return
getNDC
().
_getDepth
();
51
}
52
53
void
NDC::inherit
(
NDC::ContextStack
* stack) {
54
getNDC
().
_inherit
(stack);
55
}
56
57
std::string
NDC::pop
() {
58
return
getNDC
().
_pop
();
59
}
60
61
void
NDC::push
(
const
std::string&
message
) {
62
if
(!
isUsedNDC
)
63
isUsedNDC
=
true
;
64
getNDC
().
_push
(message);
65
}
66
67
void
NDC::setMaxDepth
(
int
maxDepth) {
68
getNDC
().
_setMaxDepth
(maxDepth);
69
}
70
71
NDC
&
NDC::getNDC
() {
72
NDC
* nDC = _nDC.
get
();
73
74
if
(!nDC) {
75
nDC =
new
NDC
();
76
_nDC.reset(nDC);
77
}
78
79
return
*nDC;
80
}
81
82
NDC::NDC
() {
83
}
84
85
NDC::~NDC
() {
86
}
87
88
void
NDC::_clear
() {
89
_stack
.clear();
90
}
91
92
NDC::ContextStack
*
NDC::_cloneStack
() {
93
return
new
ContextStack
(
_stack
);
94
}
95
96
const
std::string&
NDC::_get
()
const
{
97
static
std::string empty =
""
;
98
99
return
(
_stack
.empty() ? empty :
_stack
.back().fullMessage);
100
}
101
102
size_t
NDC::_getDepth
()
const
{
103
return
_stack
.size();
104
}
105
106
void
NDC::_inherit
(
NDC::ContextStack
* stack) {
107
_stack
= *stack;
108
}
109
110
std::string
NDC::_pop
() {
111
std::string result =
_stack
.back().message;
112
_stack
.pop_back();
113
return
result;
114
}
115
116
void
NDC::_push
(
const
std::string&
message
) {
117
if
(
_stack
.empty()) {
118
_stack
.push_back(
DiagnosticContext
(message));
119
}
else
{
120
_stack
.push_back(
DiagnosticContext
(message,
_stack
.back()));
121
}
122
}
123
124
void
NDC::_setMaxDepth
(
int
maxDepth) {
125
// XXX no maximum
126
}
127
128
}
log4cpp::threading::ThreadLocalDataHolder
Definition:
BoostThreads.hh:42
log4cpp::NDC::_push
virtual void _push(const std::string &message)
Definition:
NDC.cpp:116
log4cpp::NDC::_stack
ContextStack _stack
Definition:
NDC.hh:177
log4cpp::NDC::_get
virtual const std::string & _get() const
Definition:
NDC.cpp:96
log4cpp::NDC::setMaxDepth
static void setMaxDepth(int maxDepth)
Definition:
NDC.cpp:67
log4cpp::NDC::DiagnosticContext::message
std::string message
Definition:
NDC.hh:83
log4cpp::NDC::_getDepth
virtual size_t _getDepth() const
Definition:
NDC.cpp:102
PortabilityImpl.hh
log4cpp::NDC::DiagnosticContext
Definition:
NDC.hh:78
log4cpp::NDC::DiagnosticContext::DiagnosticContext
DiagnosticContext(const std::string &message)
Definition:
NDC.cpp:16
log4cpp::NDC::getNDC
static NDC & getNDC()
Definition:
NDC.cpp:71
log4cpp::NDC::get
static const std::string & get()
Definition:
NDC.cpp:42
log4cpp::NDC::ContextStack
std::vector< DiagnosticContext > ContextStack
Definition:
NDC.hh:87
NDC.hh
log4cpp::NDC::_setMaxDepth
virtual void _setMaxDepth(int maxDepth)
Definition:
NDC.cpp:124
log4cpp::NDC::_inherit
virtual void _inherit(ContextStack *stack)
Definition:
NDC.cpp:106
log4cpp::NDC::NDC
NDC()
Definition:
NDC.cpp:82
log4cpp
Definition:
AbortAppender.hh:16
log4cpp::NDC
Definition:
NDC.hh:69
log4cpp::NDC::isUsedNDC
static bool isUsedNDC
Definition:
NDC.hh:74
log4cpp::NDC::push
static void push(const std::string &message)
Definition:
NDC.cpp:61
log4cpp::NDC::getDepth
static size_t getDepth()
Definition:
NDC.cpp:49
log4cpp::NDC::_clear
virtual void _clear()
Definition:
NDC.cpp:88
log4cpp::NDC::inherit
static void inherit(ContextStack *stack)
Definition:
NDC.cpp:53
log4cpp::NDC::cloneStack
static ContextStack * cloneStack()
Definition:
NDC.cpp:38
log4cpp::NDC::_pop
virtual std::string _pop()
Definition:
NDC.cpp:110
log4cpp::NDC::_cloneStack
virtual ContextStack * _cloneStack()
Definition:
NDC.cpp:92
log4cpp::NDC::emptyString
static const std::string emptyString
Definition:
NDC.hh:75
Threading.hh
log4cpp::NDC::DiagnosticContext::fullMessage
std::string fullMessage
Definition:
NDC.hh:84
log4cpp::NDC::~NDC
virtual ~NDC()
Definition:
NDC.cpp:85
log4cpp::NDC::pop
static std::string pop()
Definition:
NDC.cpp:57
log4cpp::NDC::clear
static void clear()
Definition:
NDC.cpp:34
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