log4cplus  2.1.0
internal.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 // Module: Log4CPLUS
3 // File: internal.h
4 // Created: 1/2009
5 // Author: Vaclav Haisman
6 //
7 //
8 // Copyright (C) 2009-2017, Vaclav Haisman. All rights reserved.
9 //
10 // Redistribution and use in source and binary forms, with or without modifica-
11 // tion, are permitted provided that the following conditions are met:
12 //
13 // 1. Redistributions of source code must retain the above copyright notice,
14 // this list of conditions and the following disclaimer.
15 //
16 // 2. Redistributions in binary form must reproduce the above copyright notice,
17 // this list of conditions and the following disclaimer in the documentation
18 // and/or other materials provided with the distribution.
19 //
20 // THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
21 // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
22 // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23 // APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
24 // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
25 // DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
26 // OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
27 // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 
37 #ifndef LOG4CPLUS_INTERNAL_INTERNAL_HEADER_
38 #define LOG4CPLUS_INTERNAL_INTERNAL_HEADER_
39 
40 #include <log4cplus/config.hxx>
41 
42 #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE)
43 #pragma once
44 #endif
45 
46 #if ! defined (INSIDE_LOG4CPLUS)
47 # error "This header must not be be used outside log4cplus' implementation files."
48 #endif
49 
50 #include <memory>
51 #include <vector>
52 #include <sstream>
53 #include <cstdio>
54 #include <log4cplus/tstring.h>
55 #include <log4cplus/streams.h>
56 #include <log4cplus/ndc.h>
57 #include <log4cplus/mdc.h>
61 
62 
63 namespace log4cplus {
64 
65 namespace internal {
66 
67 
70 extern log4cplus::tstring const empty_str;
71 
72 
74 {
77 
78  void
79  reset ()
80  {
81  uc_q_str_valid = false;
82  q_str_valid = false;
83  s_str_valid = false;
84  ret.clear ();
85  }
86 
93  std::vector<tchar> buffer;
97 };
98 
99 
101 {
104 
107  std::string chstr;
108 };
109 
110 
113 {
116 
129  std::FILE * fnull;
131 };
132 
133 
135 
136 // TLS key whose value is pointer struct per_thread_data.
137 extern log4cplus::thread::impl::tls_key_type tls_storage_key;
138 
139 
140 #if ! defined (LOG4CPLUS_SINGLE_THREADED) \
141  && defined (LOG4CPLUS_THREAD_LOCAL_VAR)
142 
143 extern LOG4CPLUS_THREAD_LOCAL_VAR per_thread_data * ptd;
144 
145 
146 inline
147 void
149 {
150  ptd = p;
151 }
152 
153 
154 inline
155 per_thread_data *
156 get_ptd (bool alloc = true)
157 {
158  if (LOG4CPLUS_UNLIKELY (! ptd && alloc))
159  return alloc_ptd ();
160 
161  // The assert() does not belong here. get_ptd() might be called by
162  // cleanup code that can handle the returned NULL pointer.
163  //assert (ptd);
164 
165  return ptd;
166 }
167 
168 
169 #else // defined (LOG4CPLUS_THREAD_LOCAL_VAR)
170 
171 
172 inline
173 void
175 {
177 }
178 
179 
180 inline
181 per_thread_data *
182 get_ptd (bool alloc = true)
183 {
184  per_thread_data * ptd
185  = reinterpret_cast<per_thread_data *>(
187 
188  if (LOG4CPLUS_UNLIKELY (! ptd && alloc))
189  return alloc_ptd ();
190 
191  return ptd;
192 }
193 
194 
195 #endif // defined (LOG4CPLUS_THREAD_LOCAL_VAR)
196 
197 
198 inline
199 tstring &
201 {
202  return get_ptd ()->thread_name;
203 }
204 
205 
206 inline
207 tstring &
209 {
210  return get_ptd ()->thread_name2;
211 }
212 
213 
214 inline
215 gft_scratch_pad &
217 {
218  return get_ptd ()->gft_sp;
219 }
220 
221 
222 inline
223 appender_sratch_pad &
225 {
226  return get_ptd ()->appender_sp;
227 }
228 
229 
230 } // namespace internal {
231 
232 
233 namespace detail
234 {
235 
237 
238 } // namespace detail
239 
240 
241 } // namespace log4cplus {
242 
243 
244 #endif // LOG4CPLUS_INTERNAL_INTERNAL_HEADER_
The internal representation of logging events.
Definition: loggingevent.h:51
#define LOG4CPLUS_UNLIKELY(cond)
Definition: config.hxx:141
LOG4CPLUS_EXPORT void clear_tostringstream(tostringstream &)
tstring & get_thread_name_str()
Definition: internal.h:200
log4cplus::tstring const empty_str
Canonical empty string.
void set_ptd(per_thread_data *p)
Definition: internal.h:174
per_thread_data * alloc_ptd()
tstring & get_thread_name2_str()
Definition: internal.h:208
gft_scratch_pad & get_gft_scratch_pad()
Definition: internal.h:216
log4cplus::thread::impl::tls_key_type tls_storage_key
appender_sratch_pad & get_appender_sp()
Definition: internal.h:224
per_thread_data * get_ptd(bool alloc=true)
Definition: internal.h:182
void tls_set_value(tls_key_type, tls_value_type)
tls_value_type tls_get_value(tls_key_type)
std::basic_string< tchar > tstring
Definition: tstring.h:39
std::basic_ostringstream< tchar > tostringstream
Definition: streams.h:42
std::map< tstring, tstring > MappedDiagnosticContextMap
Definition: mdc.h:43
std::deque< DiagnosticContext > DiagnosticContextStack
Definition: ndc.h:43
This header defined the NDC class.
std::vector< tchar > buffer
Definition: internal.h:93
MappedDiagnosticContextMap mdc_map
Definition: internal.h:121
spi::InternalLoggingEvent forced_log_ev
Definition: internal.h:128
DiagnosticContextStack ndc_dcs
Definition: internal.h:120
log4cplus::tstring thread_name
Definition: internal.h:122
log4cplus::helpers::snprintf_buf snprintf_buf
Definition: internal.h:130
log4cplus::tstring thread_name2
Definition: internal.h:123
appender_sratch_pad appender_sp
Definition: internal.h:125
#define LOG4CPLUS_EXPORT
Definition: win32.h:141