Apache Log4cxx  Version 1.1.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
26 {
27 
90 class LOG4CXX_EXPORT NDC
91 {
92  public:
96  typedef std::pair<LogString, LogString> DiagnosticContext;
97  typedef std::stack<DiagnosticContext> Stack;
98 
111  NDC(const std::string& message);
112 
118  ~NDC();
119 
125  static void clear();
126 
138  static Stack* cloneStack();
139 
152  static void inherit(Stack* stack);
153 
160  static bool get(LogString& dest);
161 
165  static int getDepth();
166 
167 
171  static bool empty();
172 
177  static LogString pop();
183  static bool pop(std::string& buf);
184 
192  static LogString peek();
198  static bool peek(std::string& buf);
199 
206  static void push(const std::string& message);
213  static void pushLS(const LogString& message);
214 
231  static void remove();
232 
233 #if LOG4CXX_WCHAR_T_API
246  NDC(const std::wstring& message);
253  static void push(const std::wstring& message);
259  static bool peek(std::wstring& dst);
265  static bool pop(std::wstring& dst);
266 #endif
267 #if LOG4CXX_UNICHAR_API
280  NDC(const std::basic_string<UniChar>& message);
287  static void push(const std::basic_string<UniChar>& message);
293  static bool peek(std::basic_string<UniChar>& dst);
299  static bool pop(std::basic_string<UniChar>& dst);
300 #endif
301 #if LOG4CXX_CFSTRING_API
314  NDC(const CFStringRef& message);
321  static void push(const CFStringRef& message);
327  static bool peek(CFStringRef& dst);
333  static bool pop(CFStringRef& dst);
334 #endif
335 
336  private:
337  NDC(const NDC&);
338  NDC& operator=(const NDC&);
339  static LogString& getMessage(DiagnosticContext& ctx);
340  static LogString& getFullMessage(DiagnosticContext& ctx);
341 }; // class NDC;
342 } // namespace log4cxx
343 
344 #endif // _LOG4CXX_NDC_H
the ndc class implements nested diagnostic contexts as defined by neil harrison in the article "patte...
Definition: ndc.h:91
static void pushLS(const LogString &message)
Push new diagnostic context information for the current thread.
NDC(const std::basic_string< UniChar > &message)
Creates a nested diagnostic context.
std::stack< DiagnosticContext > Stack
Definition: ndc.h:97
static void push(const std::basic_string< UniChar > &message)
Push new diagnostic context information for the current thread.
static void push(const CFStringRef &message)
Push new diagnostic context information for the current thread.
~NDC()
Removes the topmost element from the NDC stack.
static bool pop(CFStringRef &dst)
Gets and removes the current NDC value.
static LogString pop()
Pop top value off stack.
static void push(const std::string &message)
Push new diagnostic context information for the current thread.
std::pair< LogString, LogString > DiagnosticContext
Pair of Message and FullMessage.
Definition: ndc.h:96
static bool pop(std::string &buf)
Pop top value off stack.
static void clear()
Clear any nested diagnostic information if any.
static bool peek(std::basic_string< UniChar > &dst)
Appends the current NDC content to the provided string.
static Stack * cloneStack()
Clone the diagnostic context for the current thread.
static void inherit(Stack *stack)
Inherit the diagnostic context of another thread.
static void push(const std::wstring &message)
Push new diagnostic context information for the current thread.
static bool empty()
Tests if the NDC is empty.
NDC(const CFStringRef &message)
Creates a nested diagnostic context.
static bool pop(std::wstring &dst)
Appends the current NDC content to the provided string and removes the value from the NDC.
static void remove()
Remove the diagnostic context for this thread.
static int getDepth()
Get the current nesting depth of this diagnostic context.
NDC(const std::string &message)
Creates a nested diagnostic context.
static bool peek(CFStringRef &dst)
Gets the current NDC value.
static LogString peek()
Looks at the last diagnostic context at the top of this NDC without removing it.
static bool pop(std::basic_string< UniChar > &dst)
Appends the current NDC content to the provided string and removes the value from the NDC.
static bool get(LogString &dest)
Get the current value of the NDC of the currrent thread.
static bool peek(std::wstring &dst)
Appends the current NDC content to the provided string.
static bool peek(std::string &buf)
Get top value without removing value.
NDC(const std::wstring &message)
Creates a nested diagnostic context.
const struct __CFString * CFStringRef
Definition: logstring.h:30
Definition: appender.h:27
std::basic_string< logchar > LogString
Definition: logstring.h:60