Apache Log4cxx  Version 1.3.0
Loading...
Searching...
No Matches
threadspecificdata.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_HELPERS_THREAD_SPECIFIC_DATA_H
19#define _LOG4CXX_HELPERS_THREAD_SPECIFIC_DATA_H
20
21#include <log4cxx/ndc.h>
22#include <log4cxx/mdc.h>
23
24namespace LOG4CXX_NS
25{
26namespace helpers
27{
33{
34 public:
38
44
48 void recycle();
49
53 static void put(const LogString& key, const LogString& val);
54
58 static void push(const LogString& val);
59
63 static void inherit(const NDC::Stack& stack);
64
69
74
78 template <typename T>
79 static std::basic_ostringstream<T>& getStringStream()
80 {
81 return getStream(T());
82 }
83
87 struct NamePair
88 {
91 };
92 using NamePairPtr = std::shared_ptr<NamePair>;
100 private:
101#if !LOG4CXX_LOGCHAR_IS_UNICHAR && !LOG4CXX_LOGCHAR_IS_WCHAR
102 static std::basic_ostringstream<logchar>& getStream(const logchar&);
103#endif
104#if LOG4CXX_WCHAR_T_API || LOG4CXX_LOGCHAR_IS_WCHAR
105 static std::basic_ostringstream<wchar_t>& getStream(const wchar_t&);
106#endif
107#if LOG4CXX_UNICHAR_API || LOG4CXX_LOGCHAR_IS_UNICHAR
108 static std::basic_ostringstream<UniChar>& getStream(const UniChar&);
109#endif
110 LOG4CXX_DECLARE_PRIVATE_MEMBER_PTR(ThreadSpecificDataPrivate, m_priv)
111};
112
113} // namespace helpers
114} // namespace log4cxx
115
116
117#endif
std::map< LogString, LogString > Map
String to string stl map.
Definition: mdc.h:50
std::stack< DiagnosticContext > Stack
Definition: ndc.h:85
This class contains all the thread-specific data in use by log4cxx.
Definition: threadspecificdata.h:33
std::shared_ptr< NamePair > NamePairPtr
Definition: threadspecificdata.h:92
static void push(const LogString &val)
Add val to the nested diagnostic context of the current thread.
static std::basic_ostringstream< T > & getStringStream()
A character outpur stream only assessable to the current thread.
Definition: threadspecificdata.h:79
ThreadSpecificData(ThreadSpecificData &&other)
static ThreadSpecificData * getCurrentData()
Gets current thread specific data.
static NamePairPtr getNames()
A reference counted pointer to the names of the current thread.
NDC::Stack & getStack()
The nested diagnostic context of the current thread.
static void put(const LogString &key, const LogString &val)
Add the key val pair to the mapped diagnostic context of the current thread.
static void inherit(const NDC::Stack &stack)
Use stack as the nested diagnostic context of the current thread.
MDC::Map & getMap()
The mapped diagnostic context of the current thread.
void recycle()
Remove current thread data from APR if the diagnostic context is empty.
#define LOG4CXX_DECLARE_PRIVATE_MEMBER_PTR(T, V)
Definition: log4cxx.h:85
#define LOG4CXX_EXPORT
Definition: log4cxx.h:101
#define LOG4CXX_NS
Definition: log4cxx.h:104
std::basic_string< logchar > LogString
Definition: logstring.h:60
unsigned short UniChar
Definition: logstring.h:38
The names assigned to the current thread.
Definition: threadspecificdata.h:88
LogString threadName
Definition: threadspecificdata.h:90
LogString idString
Definition: threadspecificdata.h:89