/src/logging-log4cxx/src/main/include/log4cxx/helpers/threadspecificdata.h
Line | Count | Source |
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 | | |
24 | | namespace LOG4CXX_NS |
25 | | { |
26 | | namespace helpers |
27 | | { |
28 | | /** |
29 | | * This class contains all the thread-specific |
30 | | * data in use by log4cxx. |
31 | | */ |
32 | | class LOG4CXX_EXPORT ThreadSpecificData |
33 | | { |
34 | | public: |
35 | | ThreadSpecificData(); |
36 | | ThreadSpecificData(ThreadSpecificData&& other); |
37 | | ~ThreadSpecificData(); |
38 | | |
39 | | /** |
40 | | * Gets current thread specific data. |
41 | | * @return a pointer that is non-null prior to application exit. |
42 | | */ |
43 | | static ThreadSpecificData* getCurrentData(); |
44 | | |
45 | | /** |
46 | | * Remove current thread data from APR if the diagnostic context is empty. |
47 | | */ |
48 | | void recycle(); |
49 | | |
50 | | /** |
51 | | * Add the \c key \c val pair to the mapped diagnostic context of the current thread |
52 | | */ |
53 | | static void put(const LogString& key, const LogString& val); |
54 | | |
55 | | /** |
56 | | * Add \c val to the nested diagnostic context of the current thread |
57 | | */ |
58 | | static void push(const LogString& val); |
59 | | |
60 | | /** |
61 | | * Use \c stack as the nested diagnostic context of the current thread |
62 | | */ |
63 | | static void inherit(const NDC::Stack& stack); |
64 | | |
65 | | /** |
66 | | * The nested diagnostic context of the current thread |
67 | | */ |
68 | | NDC::Stack& getStack(); |
69 | | |
70 | | /** |
71 | | * The mapped diagnostic context of the current thread |
72 | | */ |
73 | | MDC::Map& getMap(); |
74 | | |
75 | | /** |
76 | | * A character output stream only assessable to the current thread |
77 | | */ |
78 | | template <typename T> |
79 | | static std::basic_ostringstream<T>& getStringStream() |
80 | 0 | { |
81 | 0 | return getStream(T()); |
82 | 0 | } Unexecuted instantiation: std::__1::basic_ostringstream<char, std::__1::char_traits<char>, std::__1::allocator<char> >& log4cxx::helpers::ThreadSpecificData::getStringStream<char>() Unexecuted instantiation: std::__1::basic_ostringstream<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> >& log4cxx::helpers::ThreadSpecificData::getStringStream<wchar_t>() |
83 | | |
84 | | /** |
85 | | * Make \c ss available for use by the current thread |
86 | | */ |
87 | | template <typename T> |
88 | | static void releaseStringStream(std::basic_ostringstream<T>& ss) |
89 | 0 | { |
90 | 0 | releaseStream(ss); |
91 | 0 | } Unexecuted instantiation: void log4cxx::helpers::ThreadSpecificData::releaseStringStream<char>(std::__1::basic_ostringstream<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) Unexecuted instantiation: void log4cxx::helpers::ThreadSpecificData::releaseStringStream<wchar_t>(std::__1::basic_ostringstream<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> >&) |
92 | | |
93 | | /** |
94 | | * The names assigned to the current thread |
95 | | */ |
96 | | struct NamePair |
97 | | { |
98 | | LogString idString; |
99 | | LogString threadName; |
100 | | }; |
101 | | using NamePairPtr = std::shared_ptr<NamePair>; |
102 | | /** |
103 | | * A reference counted pointer to the names of the current thread. |
104 | | * |
105 | | * String references will remain valid |
106 | | * for the lifetime of this pointer (i.e. even after thread termination). |
107 | | */ |
108 | | static NamePairPtr getNames(); |
109 | | private: |
110 | | static std::basic_ostringstream<char>& getStream(const char&); |
111 | | static void releaseStream(std::basic_ostringstream<char>&); |
112 | | |
113 | | #if LOG4CXX_WCHAR_T_API || LOG4CXX_LOGCHAR_IS_WCHAR |
114 | | static std::basic_ostringstream<wchar_t>& getStream(const wchar_t&); |
115 | | static void releaseStream(std::basic_ostringstream<wchar_t>&); |
116 | | #endif |
117 | | #if LOG4CXX_UNICHAR_API || LOG4CXX_LOGCHAR_IS_UNICHAR |
118 | | static std::basic_ostringstream<UniChar>& getStream(const UniChar&); |
119 | | static void releaseStream(std::basic_ostringstream<UniChar>&); |
120 | | #endif |
121 | | LOG4CXX_DECLARE_PRIVATE_MEMBER_PTR(ThreadSpecificDataPrivate, m_priv) |
122 | | }; |
123 | | |
124 | | } // namespace helpers |
125 | | } // namespace log4cxx |
126 | | |
127 | | |
128 | | #endif |