log4cplus  2.0.5
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 
106  {
107  public:
116  void clear();
117 
132 
147  void inherit(const DiagnosticContextStack& stack);
148 
152  log4cplus::tstring const & get() const;
153 
159  std::size_t getDepth() const;
160 
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>
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 
279 
280 
285  {
286  // Ctors
288  DiagnosticContext const * parent);
289  DiagnosticContext(tchar const * message,
290  DiagnosticContext const * parent);
292  DiagnosticContext(tchar const * message);
294  DiagnosticContext & operator = (DiagnosticContext const &);
297 
299 
300  // Data
303  };
304 
305 
311  public:
313  explicit NDCContextCreator(const log4cplus::tstring& msg);
314  explicit NDCContextCreator(tchar const * msg);
315 
316  NDCContextCreator() = delete;
319  NDCContextCreator & operator= (NDCContextCreator const &) = delete;
320  NDCContextCreator & operator= (NDCContextCreator &&) = delete;
321 
324  };
325 
326 } // end namespace log4cplus
327 
328 
329 #endif // _LO4CPLUS_NDC_HEADER_
tstring.h
log4cplus::NDC::~NDC
virtual ~NDC()
log4cplus
Definition: appender.h:46
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
log4cplus::NDC::pop_void
void pop_void()
Same as pop() but without the return value.
log4cplus::tstring
std::basic_string< tchar > tstring
Definition: tstring.h:39
log4cplus::NDC::remove
void remove()
Remove the diagnostic context for this thread.
log4cplus::NDC::push
void push(const log4cplus::tstring &message)
Push new diagnostic context information for the current thread.
log4cplus::NDC::peek
log4cplus::tstring const & peek() const
Looks at the last diagnostic context at the top of this NDC without removing it.
log4cplus::DiagnosticContext::DiagnosticContext
DiagnosticContext(DiagnosticContext const &)
log4cplus::NDC::clear
void clear()
Clear any nested diagnostic information if any.
log4cplus::NDC::cloneStack
DiagnosticContextStack cloneStack() const
Clone the diagnostic context for the current thread.
log4cplus::DiagnosticContext::DiagnosticContext
DiagnosticContext(tchar const *message, DiagnosticContext const *parent)
log4cplus::NDC::inherit
void inherit(const DiagnosticContextStack &stack)
Inherit the diagnostic context of another thread.
log4cplus::DiagnosticContext::swap
void swap(DiagnosticContext &)
log4cplus::NDCContextCreator::~NDCContextCreator
~NDCContextCreator()
Pops the NDC stack.
log4cplus::NDC::setMaxDepth
void setMaxDepth(std::size_t maxDepth)
Set maximum depth of this diagnostic context.
log4cplus::tchar
char tchar
Definition: tchar.h:56
log4cplus::DiagnosticContext
This is the internal object that is stored on the NDC stack.
Definition: ndc.h:285
config.hxx
log4cplus::DiagnosticContext::DiagnosticContext
DiagnosticContext(DiagnosticContext &&)
log4cplus::NDC
The NDC class implements nested diagnostic contexts as defined by Neil Harrison in the article "Patte...
Definition: ndc.h:106
log4cplus::NDC::pop
log4cplus::tstring pop()
Clients should call this method before leaving a diagnostic context.
log4cplus::DiagnosticContext::fullMessage
log4cplus::tstring fullMessage
Definition: ndc.h:302
log4cplus::NDCContextCreator::NDCContextCreator
NDCContextCreator(const log4cplus::tstring &msg)
Pushes msg onto the NDC stack.
log4cplus::NDC::push
void push(tchar const *message)
log4cplus::NDCContextCreator::NDCContextCreator
NDCContextCreator(NDCContextCreator &&)=delete
log4cplus::DiagnosticContext::DiagnosticContext
DiagnosticContext(const log4cplus::tstring &message)
log4cplus::NDCContextCreator::NDCContextCreator
NDCContextCreator()=delete
LOG4CPLUS_EXPORT
#define LOG4CPLUS_EXPORT
Definition: win32.h:141
log4cplus::DiagnosticContext::DiagnosticContext
DiagnosticContext(const log4cplus::tstring &message, DiagnosticContext const *parent)
log4cplus::DiagnosticContext::DiagnosticContext
DiagnosticContext(tchar const *message)
log4cplus::DiagnosticContextStack
std::deque< DiagnosticContext > DiagnosticContextStack
Definition: ndc.h:43
log4cplus::NDCContextCreator::NDCContextCreator
NDCContextCreator(tchar const *msg)
log4cplus::NDC::get
log4cplus::tstring const & get() const
Used when printing the diagnostic context.
log4cplus::DiagnosticContext::message
log4cplus::tstring message
Definition: ndc.h:301
log4cplus::NDCContextCreator::NDCContextCreator
NDCContextCreator(NDCContextCreator const &)=delete
LOG4CPLUS_PRIVATE
#define LOG4CPLUS_PRIVATE
Definition: config.hxx:53
log4cplus::NDC::getDepth
std::size_t getDepth() const
Get the current nesting depth of this diagnostic context.
log4cplus::NDC::NDC
NDC()
log4cplus::getNDC
LOG4CPLUS_EXPORT NDC & getNDC()
Return a reference to the singleton object.