ndc.h
Go to the documentation of this file.
// -*- C++ -*-
// Module: Log4CPLUS
// File: ndc.h
// Created: 6/2001
// Author: Tad E. Smith
//
//
// Copyright 2001-2017 Tad E. Smith
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef _LO4CPLUS_NDC_HEADER_
#define _LO4CPLUS_NDC_HEADER_
#include <log4cplus/config.hxx>
#if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE)
#pragma once
#endif
#include <log4cplus/tstring.h>
#include <map>
#include <deque>
namespace log4cplus {
// Forward declarations
struct DiagnosticContext;
typedef std::deque<DiagnosticContext> DiagnosticContextStack;
class LOG4CPLUS_EXPORT NDC
{
public:
void clear();
DiagnosticContextStack cloneStack() const;
void inherit(const DiagnosticContextStack& stack);
log4cplus::tstring const & get() const;
std::size_t getDepth() const;
log4cplus::tstring pop();
void pop_void ();
log4cplus::tstring const & peek() const;
void push(const log4cplus::tstring& message);
void push(tchar const * message);
void remove();
void setMaxDepth(std::size_t maxDepth);
// Public ctor but only to be used by internal::DefaultContext.
NDC();
// Dtor
virtual ~NDC();
private:
// Methods
LOG4CPLUS_PRIVATE static DiagnosticContextStack* getPtr();
template <typename StringType>
LOG4CPLUS_PRIVATE
void push_worker (StringType const &);
// Disallow construction (and copying) except by getNDC()
NDC(const NDC&);
NDC& operator=(const NDC&);
};
LOG4CPLUS_EXPORT NDC& getNDC();
struct LOG4CPLUS_EXPORT DiagnosticContext
{
// Ctors
DiagnosticContext(const log4cplus::tstring& message,
DiagnosticContext const * parent);
DiagnosticContext(tchar const * message,
DiagnosticContext const * parent);
DiagnosticContext(const log4cplus::tstring& message);
DiagnosticContext(tchar const * message);
DiagnosticContext(DiagnosticContext const &);
DiagnosticContext & operator = (DiagnosticContext const &);
DiagnosticContext(DiagnosticContext &&);
DiagnosticContext & operator = (DiagnosticContext &&);
void swap (DiagnosticContext &);
// Data
log4cplus::tstring message;
log4cplus::tstring fullMessage;
};
class LOG4CPLUS_EXPORT NDCContextCreator {
public:
explicit NDCContextCreator(const log4cplus::tstring& msg);
explicit NDCContextCreator(tchar const * msg);
NDCContextCreator() = delete;
NDCContextCreator(NDCContextCreator const &) = delete;
NDCContextCreator(NDCContextCreator &&) = delete;
NDCContextCreator & operator= (NDCContextCreator const &) = delete;
NDCContextCreator & operator= (NDCContextCreator &&) = delete;
~NDCContextCreator();
};
} // end namespace log4cplus
#endif // _LO4CPLUS_NDC_HEADER_
log4cplus::NDCContextCreator::~NDCContextCreator
~NDCContextCreator()
Pops the NDC stack.
log4cplus::NDCContextCreator::NDCContextCreator
NDCContextCreator(NDCContextCreator const &)=delete
log4cplus::NDCContextCreator::NDCContextCreator
NDCContextCreator(const log4cplus::tstring &msg)
Pushes msg onto the NDC stack.
log4cplus::NDCContextCreator::NDCContextCreator
NDCContextCreator(tchar const *msg)
log4cplus::NDCContextCreator::NDCContextCreator
NDCContextCreator()=delete
log4cplus::NDCContextCreator::NDCContextCreator
NDCContextCreator(NDCContextCreator &&)=delete
log4cplus::NDC
The NDC class implements nested diagnostic contexts as defined by Neil Harrison in the article "Patte...
Definition ndc.h:106
log4cplus::NDC::getDepth
std::size_t getDepth() const
Get the current nesting depth of this diagnostic context.
log4cplus::NDC::pop
log4cplus::tstring pop()
Clients should call this method before leaving a diagnostic context.
log4cplus::NDC::remove
void remove()
Remove the diagnostic context for this thread.
log4cplus::NDC::~NDC
virtual ~NDC()
log4cplus::NDC::push
void push(tchar const *message)
log4cplus::NDC::push
void push(const log4cplus::tstring &message)
Push new diagnostic context information for the current thread.
log4cplus::NDC::inherit
void inherit(const DiagnosticContextStack &stack)
Inherit the diagnostic context of another 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::NDC::cloneStack
DiagnosticContextStack cloneStack() const
Clone the diagnostic context for the current thread.
log4cplus::NDC::clear
void clear()
Clear any nested diagnostic information if any.
log4cplus::NDC::NDC
NDC()
log4cplus::NDC::get
log4cplus::tstring const & get() const
Used when printing the diagnostic context.
log4cplus::NDC::pop_void
void pop_void()
Same as pop() but without the return value.
log4cplus::NDC::setMaxDepth
void setMaxDepth(std::size_t maxDepth)
Set maximum depth of this diagnostic context.
config.hxx
LOG4CPLUS_PRIVATE
#define LOG4CPLUS_PRIVATE
Definition config.hxx:53
log4cplus
Definition appender.h:46
log4cplus::getNDC
LOG4CPLUS_EXPORT NDC & getNDC()
Return a reference to the singleton object.
log4cplus::tstring
std::basic_string< tchar > tstring
Definition tstring.h:39
log4cplus::tchar
char tchar
Definition tchar.h:56
log4cplus::DiagnosticContextStack
std::deque< DiagnosticContext > DiagnosticContextStack
Definition ndc.h:44
log4cplus::DiagnosticContext
This is the internal object that is stored on the NDC stack.
Definition ndc.h:285
log4cplus::DiagnosticContext::DiagnosticContext
DiagnosticContext(DiagnosticContext &&)
log4cplus::DiagnosticContext::message
log4cplus::tstring message
Definition ndc.h:301
log4cplus::DiagnosticContext::fullMessage
log4cplus::tstring fullMessage
Definition ndc.h:302
log4cplus::DiagnosticContext::DiagnosticContext
DiagnosticContext(const log4cplus::tstring &message, DiagnosticContext const *parent)
log4cplus::DiagnosticContext::DiagnosticContext
DiagnosticContext(tchar const *message)
log4cplus::DiagnosticContext::swap
void swap(DiagnosticContext &)
log4cplus::DiagnosticContext::DiagnosticContext
DiagnosticContext(tchar const *message, DiagnosticContext const *parent)
log4cplus::DiagnosticContext::DiagnosticContext
DiagnosticContext(const log4cplus::tstring &message)
log4cplus::DiagnosticContext::DiagnosticContext
DiagnosticContext(DiagnosticContext const &)
tstring.h
LOG4CPLUS_EXPORT
#define LOG4CPLUS_EXPORT
Definition win32.h:141