/src/dcmtk/oflog/libsrc/logevent.cc
Line | Count | Source |
1 | | // Module: Log4CPLUS |
2 | | // File: loggingevent.cxx |
3 | | // Created: 6/2003 |
4 | | // Author: Tad E. Smith |
5 | | // |
6 | | // |
7 | | // Copyright 2003-2010 Tad E. Smith |
8 | | // |
9 | | // Licensed under the Apache License, Version 2.0 (the "License"); |
10 | | // you may not use this file except in compliance with the License. |
11 | | // You may obtain a copy of the License at |
12 | | // |
13 | | // http://www.apache.org/licenses/LICENSE-2.0 |
14 | | // |
15 | | // Unless required by applicable law or agreed to in writing, software |
16 | | // distributed under the License is distributed on an "AS IS" BASIS, |
17 | | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
18 | | // See the License for the specific language governing permissions and |
19 | | // limitations under the License. |
20 | | |
21 | | #include "dcmtk/oflog/spi/logevent.h" |
22 | | #include "dcmtk/oflog/internal/internal.h" |
23 | | #include <algorithm> |
24 | | |
25 | | |
26 | | namespace dcmtk { |
27 | | namespace log4cplus { namespace spi { |
28 | | |
29 | | |
30 | | static const int DCMTK_LOG4CPLUS_DEFAULT_TYPE = 1; |
31 | | |
32 | | |
33 | | /////////////////////////////////////////////////////////////////////////////// |
34 | | // InternalLoggingEvent ctors and dtor |
35 | | /////////////////////////////////////////////////////////////////////////////// |
36 | | |
37 | | InternalLoggingEvent::InternalLoggingEvent(const log4cplus::tstring& logger, |
38 | | LogLevel loglevel, const log4cplus::tstring& message_, const char* filename, |
39 | | int line_) |
40 | 0 | : message(message_) |
41 | 0 | , loggerName(logger) |
42 | 0 | , ll(loglevel) |
43 | 0 | , ndc() |
44 | 0 | , mdc() |
45 | 0 | , thread() |
46 | 0 | , thread2() |
47 | 0 | , timestamp(log4cplus::helpers::Time::gettimeofday()) |
48 | 0 | , file(filename |
49 | 0 | ? DCMTK_LOG4CPLUS_C_STR_TO_TSTRING(filename) |
50 | 0 | : log4cplus::tstring()) |
51 | 0 | , function () |
52 | 0 | , line(line_) |
53 | 0 | , threadCached(false) |
54 | 0 | , thread2Cached(false) |
55 | 0 | , ndcCached(false) |
56 | 0 | , mdcCached(false) |
57 | 0 | { |
58 | 0 | } |
59 | | |
60 | | |
61 | | InternalLoggingEvent::InternalLoggingEvent(const log4cplus::tstring& logger, |
62 | | LogLevel loglevel, const log4cplus::tstring& ndc_, |
63 | | MappedDiagnosticContextMap const & mdc_, const log4cplus::tstring& message_, |
64 | | const log4cplus::tstring& thread_, log4cplus::helpers::Time time, |
65 | | const log4cplus::tstring& file_, int line_) |
66 | 0 | : message(message_) |
67 | 0 | , loggerName(logger) |
68 | 0 | , ll(loglevel) |
69 | 0 | , ndc(ndc_) |
70 | 0 | , mdc(mdc_) |
71 | 0 | , thread(thread_) |
72 | 0 | , thread2() |
73 | 0 | , timestamp(time) |
74 | 0 | , file(file_) |
75 | 0 | , function () |
76 | 0 | , line(line_) |
77 | 0 | , threadCached(true) |
78 | 0 | , thread2Cached(true) |
79 | 0 | , ndcCached(true) |
80 | 0 | , mdcCached(true) |
81 | 0 | { |
82 | 0 | } |
83 | | |
84 | | |
85 | | InternalLoggingEvent::InternalLoggingEvent () |
86 | 6 | : message() |
87 | 6 | , loggerName() |
88 | 6 | , ll (NOT_SET_LOG_LEVEL) |
89 | 6 | , ndc() |
90 | 6 | , mdc() |
91 | 6 | , thread() |
92 | 6 | , thread2() |
93 | 6 | , timestamp() |
94 | 6 | , file() |
95 | 6 | , function () |
96 | 6 | , line(0) |
97 | 6 | , threadCached(false) |
98 | 6 | , thread2Cached(false) |
99 | 6 | , ndcCached(false) |
100 | 6 | , mdcCached(false) |
101 | 6 | { } |
102 | | |
103 | | |
104 | | InternalLoggingEvent::InternalLoggingEvent( |
105 | | const log4cplus::spi::InternalLoggingEvent& rhs) |
106 | 0 | : message(rhs.getMessage()) |
107 | 0 | , loggerName(rhs.getLoggerName()) |
108 | 0 | , ll(rhs.getLogLevel()) |
109 | 0 | , ndc(rhs.getNDC()) |
110 | 0 | , mdc(rhs.getMDCCopy()) |
111 | 0 | , thread(rhs.getThread()) |
112 | 0 | , thread2(rhs.getThread2()) |
113 | 0 | , timestamp(rhs.getTimestamp()) |
114 | 0 | , file(rhs.getFile()) |
115 | 0 | , function(rhs.getFunction()) |
116 | 0 | , line(rhs.getLine()) |
117 | 0 | , threadCached(true) |
118 | 0 | , thread2Cached(true) |
119 | 0 | , ndcCached(true) |
120 | 0 | , mdcCached(true) |
121 | 0 | { |
122 | 0 | } |
123 | | |
124 | | |
125 | | InternalLoggingEvent::~InternalLoggingEvent() |
126 | 0 | { |
127 | 0 | } |
128 | | |
129 | | |
130 | | |
131 | | /////////////////////////////////////////////////////////////////////////////// |
132 | | // InternalLoggingEvent static methods |
133 | | /////////////////////////////////////////////////////////////////////////////// |
134 | | |
135 | | unsigned int |
136 | | InternalLoggingEvent::getDefaultType() |
137 | 0 | { |
138 | 0 | return DCMTK_LOG4CPLUS_DEFAULT_TYPE; |
139 | 0 | } |
140 | | |
141 | | |
142 | | |
143 | | /////////////////////////////////////////////////////////////////////////////// |
144 | | // InternalLoggingEvent implementation |
145 | | /////////////////////////////////////////////////////////////////////////////// |
146 | | |
147 | | void |
148 | | InternalLoggingEvent::setLoggingEvent (const log4cplus::tstring & logger, |
149 | | LogLevel loglevel, const log4cplus::tstring & msg, const char * filename, |
150 | | int fline) |
151 | 482k | { |
152 | | // This could be implemented using the swap idiom: |
153 | | // |
154 | | // InternalLoggingEvent (logger, loglevel, msg, filename, fline).swap (*this); |
155 | | // |
156 | | // But that defeats the optimization of using thread local instance |
157 | | // of InternalLoggingEvent to avoid memory allocation. |
158 | | |
159 | 482k | loggerName = logger; |
160 | 482k | ll = loglevel; |
161 | 482k | message = msg; |
162 | 482k | timestamp = helpers::Time::gettimeofday(); |
163 | 482k | if (filename) |
164 | 482k | file = DCMTK_LOG4CPLUS_C_STR_TO_TSTRING (filename); |
165 | 0 | else |
166 | 0 | file.clear (); |
167 | 482k | line = fline; |
168 | 482k | threadCached = false; |
169 | 482k | thread2Cached = false; |
170 | 482k | ndcCached = false; |
171 | 482k | mdcCached = false; |
172 | 482k | } |
173 | | |
174 | | |
175 | | void |
176 | | InternalLoggingEvent::setFunction (char const * func) |
177 | 482k | { |
178 | 482k | function = DCMTK_LOG4CPLUS_C_STR_TO_TSTRING (func); |
179 | 482k | } |
180 | | |
181 | | |
182 | | void |
183 | | InternalLoggingEvent::setFunction (log4cplus::tstring const & func) |
184 | 0 | { |
185 | 0 | function = func; |
186 | 0 | } |
187 | | |
188 | | |
189 | | const log4cplus::tstring& |
190 | | InternalLoggingEvent::getMessage() const |
191 | 964k | { |
192 | 964k | return message; |
193 | 964k | } |
194 | | |
195 | | |
196 | | unsigned int |
197 | | InternalLoggingEvent::getType() const |
198 | 0 | { |
199 | 0 | return DCMTK_LOG4CPLUS_DEFAULT_TYPE; |
200 | 0 | } |
201 | | |
202 | | |
203 | | |
204 | | OFrvalue<OFunique_ptr<InternalLoggingEvent> > |
205 | | InternalLoggingEvent::clone() const |
206 | 0 | { |
207 | 0 | return OFrvalue<OFunique_ptr<InternalLoggingEvent> >(new InternalLoggingEvent(*this)); |
208 | 0 | } |
209 | | |
210 | | |
211 | | tstring const & |
212 | | InternalLoggingEvent::getMDC (tstring const & key) const |
213 | 0 | { |
214 | 0 | MappedDiagnosticContextMap const & mdc_ = getMDCCopy (); |
215 | 0 | MappedDiagnosticContextMap::const_iterator it = mdc_.find (key); |
216 | 0 | if (it != mdc_.end ()) |
217 | 0 | return it->second; |
218 | 0 | else |
219 | 0 | return internal::empty_str; |
220 | 0 | } |
221 | | |
222 | | |
223 | | |
224 | | InternalLoggingEvent & |
225 | | InternalLoggingEvent::operator = (const InternalLoggingEvent& rhs) |
226 | 0 | { |
227 | 0 | InternalLoggingEvent (rhs).swap (*this); |
228 | 0 | return *this; |
229 | 0 | } |
230 | | |
231 | | |
232 | | void |
233 | | InternalLoggingEvent::gatherThreadSpecificData () const |
234 | 0 | { |
235 | 0 | getNDC (); |
236 | 0 | getMDCCopy (); |
237 | 0 | getThread (); |
238 | 0 | getThread2 (); |
239 | 0 | } |
240 | | |
241 | | |
242 | | void |
243 | | InternalLoggingEvent::swap (InternalLoggingEvent & other) |
244 | 0 | { |
245 | 0 | using STD_NAMESPACE swap; |
246 | |
|
247 | 0 | swap (message, other.message); |
248 | 0 | swap (loggerName, other.loggerName); |
249 | 0 | swap (ll, other.ll); |
250 | 0 | swap (ndc, other.ndc); |
251 | 0 | swap (mdc, other.mdc); |
252 | 0 | swap (thread, other.thread); |
253 | 0 | swap (thread2, other.thread2); |
254 | 0 | swap (timestamp, other.timestamp); |
255 | 0 | swap (file, other.file); |
256 | 0 | swap (function, other.function); |
257 | 0 | swap (line, other.line); |
258 | 0 | swap (threadCached, other.threadCached); |
259 | 0 | swap (ndcCached, other.ndcCached); |
260 | 0 | } |
261 | | |
262 | | |
263 | | } } // namespace log4cplus { namespace spi { |
264 | | } // end namespace dcmtk |