Apache Log4cxx  Version 1.5.0
ndc.h
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #ifndef _LOG4CXX_NDC_H
19 #define _LOG4CXX_NDC_H
20 
21 #include <log4cxx/log4cxx.h>
22 #include <log4cxx/logstring.h>
23 #include <stack>
24 
25 namespace LOG4CXX_NS
26 {
27 
78 class LOG4CXX_EXPORT NDC
79 {
80  public:
84  typedef std::pair<LogString, LogString> DiagnosticContext;
85  typedef std::stack<DiagnosticContext> Stack;
86 
93  NDC(const std::string& message);
94 
100  ~NDC();
101 
107  static void clear();
108 
120  static Stack* cloneStack();
121 
134  static void inherit(Stack* stack);
135 
142  static bool get(LogString& dest);
143 
147  static int getDepth();
148 
149 
153  static bool empty();
154 
162  static LogString pop();
168  static bool pop(std::string& buf);
169 
177  static LogString peek();
183  static bool peek(std::string& buf);
184 
191  static void push(const std::string& message);
198  static void pushLS(const LogString& message);
199 
206  static void remove();
207 
208 #if LOG4CXX_WCHAR_T_API
209 
215  NDC(const std::wstring& message);
220  static void push(const std::wstring& message);
226  static bool peek(std::wstring& dst);
232  static bool pop(std::wstring& dst);
233 #endif
234 #if LOG4CXX_UNICHAR_API
235 
241  NDC(const std::basic_string<UniChar>& message);
248  static void push(const std::basic_string<UniChar>& message);
254  static bool peek(std::basic_string<UniChar>& dst);
260  static bool pop(std::basic_string<UniChar>& dst);
261 #endif
262 #if LOG4CXX_CFSTRING_API
263 
269  NDC(const CFStringRef& message);
274  static void push(const CFStringRef& message);
280  static bool peek(CFStringRef& dst);
286  static bool pop(CFStringRef& dst);
287 #endif
288 
289  static const LogString& getMessage(const DiagnosticContext& ctx);
290  static const LogString& getFullMessage(const DiagnosticContext& ctx);
291  private:
292  NDC(const NDC&);
293  NDC& operator=(const NDC&);
294 }; // class NDC;
295 } // namespace log4cxx
296 
297 #endif // _LOG4CXX_NDC_H
logstring.h
log4cxx::LogString
std::basic_string< logchar > LogString
Definition: logstring.h:60
log4cxx::NDC::pushLS
static void pushLS(const LogString &message)
Add message to the stack associated with the current thread.
log4cxx::NDC::get
static bool get(LogString &dest)
Get the current value of the NDC of the currrent thread.
log4cxx::NDC::peek
static bool peek(std::wstring &dst)
Append to dst the top value in the stack associated with the current thread without removing it.
log4cxx::NDC::NDC
NDC(const std::string &message)
Add message onto the context stack.
CFStringRef
const struct __CFString * CFStringRef
Definition: logstring.h:30
log4cxx::NDC::pop
static LogString pop()
Get the value at the top of the stack associated with the current thread and then remove it.
log4cxx::NDC::push
static void push(const CFStringRef &message)
Add message to the stack associated with the current thread.
log4cxx::NDC::push
static void push(const std::string &message)
Add message to the stack associated with the current thread.
log4cxx::NDC::peek
static LogString peek()
Get the value at the top of the stack associated with the current thread without removing it.
log4cxx::NDC::inherit
static void inherit(Stack *stack)
Inherit the diagnostic context of another thread.
log4cxx::NDC::NDC
NDC(const std::wstring &message)
Add message onto the context stack.
log4cxx::NDC::pop
static bool pop(std::string &buf)
Append to buf the top value in the stack associated with the current thread and then remove it.
log4cxx::NDC::clear
static void clear()
Clear any nested diagnostic information if any.
log4cxx::NDC::pop
static bool pop(std::wstring &dst)
Appends the current NDC content to the provided string and removes the value from the NDC.
log4cxx::NDC::pop
static bool pop(std::basic_string< UniChar > &dst)
Append to dst the top value in the stack associated with the current thread and then remove it.
log4cxx::NDC::peek
static bool peek(std::string &buf)
Append to buf the top value in the stack associated with the current thread without removing it.
log4cxx::NDC::Stack
std::stack< DiagnosticContext > Stack
Definition: ndc.h:85
log4cxx::NDC::push
static void push(const std::wstring &message)
Add message to the stack associated with the current thread.
log4cxx::NDC::DiagnosticContext
std::pair< LogString, LogString > DiagnosticContext
Pair of Message and FullMessage.
Definition: ndc.h:84
log4cxx::NDC::pop
static bool pop(CFStringRef &dst)
Append to dst the top value in the stack associated with the current thread and then remove it.
log4cxx::NDC::push
static void push(const std::basic_string< UniChar > &message)
Add message to the stack associated with the current thread.
log4cxx::NDC::remove
static void remove()
Remove all the diagnostic context data for this thread.
log4cxx::NDC::empty
static bool empty()
Tests if the NDC is empty.
log4cxx::NDC::~NDC
~NDC()
Remove the topmost element from the context stack associated with the current thread.
log4cxx::NDC::getFullMessage
static const LogString & getFullMessage(const DiagnosticContext &ctx)
log4cxx::NDC::peek
static bool peek(CFStringRef &dst)
Append to dst the top value in the stack associated with the current thread without removing it.
log4cxx::NDC::getMessage
static const LogString & getMessage(const DiagnosticContext &ctx)
log4cxx::NDC::getDepth
static int getDepth()
Get the current nesting depth of this diagnostic context.
log4cxx::NDC::peek
static bool peek(std::basic_string< UniChar > &dst)
Append to dst the top value in the stack associated with the current thread without removing it.
log4cxx::NDC::NDC
NDC(const std::basic_string< UniChar > &message)
Add message onto the context stack.
log4cxx::NDC::NDC
NDC(const CFStringRef &message)
Add message onto the context stack.
log4cxx::NDC::cloneStack
static Stack * cloneStack()
Clone the diagnostic context for the current thread.
log4cxx::NDC
A Nested Diagnostic Context, or NDC in short, is an instrument to distinguish interleaved log output ...
Definition: ndc.h:79