log4cplus
2.0.0
include
log4cplus
ndc.h
Go to the documentation of this file.
1
// -*- C++ -*-
2
// Module: Log4CPLUS
3
// File: ndc.h
4
// Created: 6/2001
5
// Author: Tad E. Smith
6
//
7
//
8
// Copyright 2001-2017 Tad E. Smith
9
//
10
// Licensed under the Apache License, Version 2.0 (the "License");
11
// you may not use this file except in compliance with the License.
12
// You may obtain a copy of the License at
13
//
14
// http://www.apache.org/licenses/LICENSE-2.0
15
//
16
// Unless required by applicable law or agreed to in writing, software
17
// distributed under the License is distributed on an "AS IS" BASIS,
18
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
// See the License for the specific language governing permissions and
20
// limitations under the License.
21
26
#ifndef _LO4CPLUS_NDC_HEADER_
27
#define _LO4CPLUS_NDC_HEADER_
28
29
#include <
log4cplus/config.hxx
>
30
31
#if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE)
32
#pragma once
33
#endif
34
35
#include <
log4cplus/tstring.h
>
36
37
#include <map>
38
#include <deque>
39
40
41
namespace
log4cplus
{
42
// Forward declarations
43
struct
DiagnosticContext
;
44
typedef
std::deque<DiagnosticContext>
DiagnosticContextStack
;
45
105
class
LOG4CPLUS_EXPORT
NDC
106
{
107
public
:
116
void
clear();
117
131
DiagnosticContextStack
cloneStack()
const
;
132
147
void
inherit(
const
DiagnosticContextStack
& stack);
148
152
log4cplus::tstring
const
& get()
const
;
153
159
std::size_t getDepth()
const
;
160
177
log4cplus::tstring
pop();
178
182
void
pop_void ();
183
193
log4cplus::tstring
const
& peek()
const
;
194
206
void
push(
const
log4cplus::tstring
& message);
207
void
push(
tchar
const
* message);
208
221
void
remove();
222
253
void
setMaxDepth(std::size_t maxDepth);
254
255
// Public ctor but only to be used by internal::DefaultContext.
256
NDC
();
257
258
// Dtor
259
virtual
~
NDC
();
260
261
private
:
262
// Methods
263
LOG4CPLUS_PRIVATE
static
DiagnosticContextStack
* getPtr();
264
265
template
<
typename
StringType>
266
LOG4CPLUS_PRIVATE
267
void
push_worker (StringType
const
&);
268
269
// Disallow construction (and copying) except by getNDC()
270
NDC
(
const
NDC
&);
271
NDC
& operator=(
const
NDC
&);
272
};
273
274
278
LOG4CPLUS_EXPORT
NDC
&
getNDC
();
279
280
284
struct
LOG4CPLUS_EXPORT
DiagnosticContext
285
{
286
// Ctors
287
DiagnosticContext
(
const
log4cplus::tstring
& message,
288
DiagnosticContext
const
* parent);
289
DiagnosticContext
(
tchar
const
* message,
290
DiagnosticContext
const
* parent);
291
DiagnosticContext
(
const
log4cplus::tstring
& message);
292
DiagnosticContext
(
tchar
const
* message);
293
DiagnosticContext
(
DiagnosticContext
const
&);
294
DiagnosticContext
& operator = (
DiagnosticContext
const
&);
295
DiagnosticContext
(
DiagnosticContext
&&);
296
DiagnosticContext
& operator = (
DiagnosticContext
&&);
297
298
void
swap (
DiagnosticContext
&);
299
300
// Data
301
log4cplus::tstring
message
;
302
log4cplus::tstring
fullMessage
;
303
};
304
305
310
class
LOG4CPLUS_EXPORT
NDCContextCreator
{
311
public
:
313
explicit
NDCContextCreator
(
const
log4cplus::tstring
& msg);
314
explicit
NDCContextCreator
(
tchar
const
* msg);
315
316
NDCContextCreator
() =
delete
;
317
NDCContextCreator
(
NDCContextCreator
const
&) =
delete
;
318
NDCContextCreator
(
NDCContextCreator
&&) =
delete
;
319
NDCContextCreator
& operator= (
NDCContextCreator
const
&) =
delete
;
320
NDCContextCreator
& operator= (
NDCContextCreator
&&) =
delete
;
321
323
~
NDCContextCreator
();
324
};
325
326
}
// end namespace log4cplus
327
328
329
#endif // _LO4CPLUS_NDC_HEADER_
LOG4CPLUS_EXPORT
#define LOG4CPLUS_EXPORT
Definition:
win32.h:141
log4cplus::DiagnosticContext
This is the internal object that is stored on the NDC stack.
Definition:
ndc.h:284
log4cplus::DiagnosticContext::message
log4cplus::tstring message
Definition:
ndc.h:301
LOG4CPLUS_PRIVATE
#define LOG4CPLUS_PRIVATE
Definition:
config.hxx:53
tstring.h
log4cplus::NDC
The NDC class implements nested diagnostic contexts as defined by Neil Harrison in the article "Patte...
Definition:
ndc.h:105
log4cplus::tchar
char tchar
Definition:
tchar.h:56
config.hxx
log4cplus::tstring
std::basic_string< tchar > tstring
Definition:
tstring.h:39
log4cplus::DiagnosticContextStack
std::deque< DiagnosticContext > DiagnosticContextStack
Definition:
ndc.h:43
log4cplus::DiagnosticContext::fullMessage
log4cplus::tstring fullMessage
Definition:
ndc.h:302
log4cplus
Definition:
appender.h:46
log4cplus::getNDC
LOG4CPLUS_EXPORT NDC & getNDC()
Return a reference to the singleton object.
log4cplus::NDCContextCreator
This class ensures that a NDC::push() call is always matched with a NDC::pop() call even in the face ...
Definition:
ndc.h:310
Generated on Sun Apr 14 2019 22:51:15 for log4cplus by
1.8.15