Apache log4cxx Version 0.13.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#if defined(_MSC_VER)
26 #pragma warning ( push )
27 #pragma warning ( disable: 4231 4251 4275 4786 )
28#endif
29
30namespace log4cxx
31{
32
95class LOG4CXX_EXPORT NDC
96{
97 public:
101 typedef std::pair<LogString, LogString> DiagnosticContext;
102 typedef std::stack<DiagnosticContext> Stack;
103
116 NDC(const std::string& message);
117
124
130 static void clear();
131
143 static Stack* cloneStack();
144
157 static void inherit(Stack* stack);
158
165 static bool get(LogString& dest);
166
170 static int getDepth();
171
172
176 static bool empty();
177
182 static LogString pop();
188 static bool pop(std::string& buf);
189
197 static LogString peek();
203 static bool peek(std::string& buf);
204
211 static void push(const std::string& message);
218 static void pushLS(const LogString& message);
219
236 static void remove();
237
238#if LOG4CXX_WCHAR_T_API
251 NDC(const std::wstring& message);
258 static void push(const std::wstring& message);
264 static bool peek(std::wstring& dst);
270 static bool pop(std::wstring& dst);
271#endif
272#if LOG4CXX_UNICHAR_API
285 NDC(const std::basic_string<UniChar>& message);
292 static void push(const std::basic_string<UniChar>& message);
298 static bool peek(std::basic_string<UniChar>& dst);
304 static bool pop(std::basic_string<UniChar>& dst);
305#endif
306#if LOG4CXX_CFSTRING_API
319 NDC(const CFStringRef& message);
326 static void push(const CFStringRef& message);
332 static bool peek(CFStringRef& dst);
338 static bool pop(CFStringRef& dst);
339#endif
340
341 private:
342 NDC(const NDC&);
343 NDC& operator=(const NDC&);
344 static LogString& getMessage(DiagnosticContext& ctx);
345 static LogString& getFullMessage(DiagnosticContext& ctx);
346}; // class NDC;
347} // namespace log4cxx
348
349#if defined(_MSC_VER)
350 #pragma warning (pop)
351#endif
352
353
354#endif // _LOG4CXX_NDC_H
the ndc class implements nested diagnostic contexts as defined by neil harrison in the article "patte...
Definition: ndc.h:96
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:102
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 Stack * cloneStack()
Clone the diagnostic context for the current thread.
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:101
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 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:36
Definition: messagehandler.h:23
std::basic_string< logchar > LogString
Definition: logstring.h:66