Menu

[2d617b]: / src / NDC.cpp  Maximize  Restore  History

Download this file

129 lines (99 with data), 2.7 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
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
* NDC.cpp
*
* Copyright 2000, LifeLine Networks BV (www.lifeline.nl). All rights reserved.
* Copyright 2000, Bastiaan Bakker. All rights reserved.
*
* See the COPYING file for the terms of usage and distribution.
*/
#include "PortabilityImpl.hh"
#include <log4cpp/NDC.hh>
#include <log4cpp/threading/Threading.hh>
namespace log4cpp {
NDC::DiagnosticContext::DiagnosticContext(const std::string& message) :
message(message),
fullMessage(message) {
}
NDC::DiagnosticContext::DiagnosticContext(const std::string& message,
const DiagnosticContext& parent) :
message(message),
fullMessage(parent.fullMessage + " " + message) {
}
bool NDC::isUsedNDC = false;
const std::string NDC::emptyString = "";
namespace {
threading::ThreadLocalDataHolder<NDC> _nDC;
}
void NDC::clear() {
getNDC()._clear();
}
NDC::ContextStack* NDC::cloneStack() {
return getNDC()._cloneStack();
}
const std::string& NDC::get() {
if (isUsedNDC)
return getNDC()._get();
else
return emptyString;
}
size_t NDC::getDepth() {
return getNDC()._getDepth();
}
void NDC::inherit(NDC::ContextStack* stack) {
getNDC()._inherit(stack);
}
std::string NDC::pop() {
return getNDC()._pop();
}
void NDC::push(const std::string& message) {
if (!isUsedNDC)
isUsedNDC = true;
getNDC()._push(message);
}
void NDC::setMaxDepth(int maxDepth) {
getNDC()._setMaxDepth(maxDepth);
}
NDC& NDC::getNDC() {
NDC* nDC = _nDC.get();
if (!nDC) {
nDC = new NDC();
_nDC.reset(nDC);
}
return *nDC;
}
NDC::NDC() {
}
NDC::~NDC() {
}
void NDC::_clear() {
_stack.clear();
}
NDC::ContextStack* NDC::_cloneStack() {
return new ContextStack(_stack);
}
const std::string& NDC::_get() const {
static std::string empty = "";
return (_stack.empty() ? empty : _stack.back().fullMessage);
}
size_t NDC::_getDepth() const {
return _stack.size();
}
void NDC::_inherit(NDC::ContextStack* stack) {
_stack = *stack;
}
std::string NDC::_pop() {
std::string result = _stack.back().message;
_stack.pop_back();
return result;
}
void NDC::_push(const std::string& message) {
if (_stack.empty()) {
_stack.push_back(DiagnosticContext(message));
} else {
_stack.push_back(DiagnosticContext(message, _stack.back()));
}
}
void NDC::_setMaxDepth(int maxDepth) {
// XXX no maximum
}
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.