source: pacpusframework/trunk/3rd/apache-log4cxx/include/log4cxx/spi/loggingevent.h@ 60

Last change on this file since 60 was 2, checked in by sgosseli, 12 years ago

Add 3rd party libraries (log4cxx).

File size: 11.1 KB
Line 
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_SPI_LOGGING_EVENT_H
19#define _LOG4CXX_SPI_LOGGING_EVENT_H
20
21#if defined(_MSC_VER)
22#pragma warning (push)
23#pragma warning ( disable: 4231 4251 4275 4786 )
24#endif
25
26
27
28#include <log4cxx/helpers/objectptr.h>
29#include <log4cxx/logstring.h>
30#include <time.h>
31#include <log4cxx/logger.h>
32#include <log4cxx/mdc.h>
33#include <log4cxx/spi/location/locationinfo.h>
34#include <vector>
35
36
37namespace log4cxx
38{
39 namespace helpers
40 {
41 class ObjectOutputStream;
42 }
43
44 namespace spi
45 {
46
47 LOG4CXX_LIST_DEF(KeySet, LogString);
48 /**
49 The internal representation of logging events. When an affirmative
50 decision is made to log then a <code>LoggingEvent</code> instance
51 is created. This instance is passed around to the different log4cxx
52 components.
53
54 <p>This class is of concern to those wishing to extend log4cxx.
55 */
56 class LOG4CXX_EXPORT LoggingEvent :
57 public virtual helpers::ObjectImpl
58 {
59 public:
60 DECLARE_LOG4CXX_OBJECT(LoggingEvent)
61 BEGIN_LOG4CXX_CAST_MAP()
62 LOG4CXX_CAST_ENTRY(LoggingEvent)
63 END_LOG4CXX_CAST_MAP()
64
65 /** For serialization only
66 */
67 LoggingEvent();
68
69 /**
70 Instantiate a LoggingEvent from the supplied parameters.
71
72 <p>Except timeStamp all the other fields of
73 <code>LoggingEvent</code> are filled when actually needed.
74 <p>
75 @param logger The logger of this event.
76 @param level The level of this event.
77 @param message The message of this event.
78 @param location location of logging request.
79 */
80 LoggingEvent(const LogString& logger,
81 const LevelPtr& level, const LogString& message,
82 const log4cxx::spi::LocationInfo& location);
83
84 ~LoggingEvent();
85
86 /** Return the level of this event. */
87 inline const LevelPtr& getLevel() const
88 { return level; }
89
90 /** Return the name of the logger. */
91 inline const LogString& getLoggerName() const {
92 return logger;
93 }
94
95 /** Return the message for this logging event. */
96 inline const LogString& getMessage() const
97 { return message; }
98
99 /** Return the message for this logging event. */
100 inline const LogString& getRenderedMessage() const
101 { return message; }
102
103 /**Returns the time when the application started,
104 in seconds elapsed since 01.01.1970.
105 */
106 static log4cxx_time_t getStartTime();
107
108 /** Return the threadName of this event. */
109 inline const LogString& getThreadName() const {
110 return threadName;
111 }
112
113 /** Return the timeStamp of this event. */
114 inline log4cxx_time_t getTimeStamp() const
115 { return timeStamp; }
116
117 /* Return the file where this log statement was written. */
118 inline const log4cxx::spi::LocationInfo& getLocationInformation() const
119 { return locationInfo; }
120
121 /**
122 * This method appends the NDC for this event to passed string. It will return the
123 * correct content even if the event was generated in a different
124 * thread or even on a different machine. The NDC#get method
125 * should <em>never</em> be called directly.
126 *
127 * @param dest destination for NDC, unchanged if NDC is not set.
128 * @return true if NDC is set.
129 */
130 bool getNDC(LogString& dest) const;
131
132 /**
133 * Writes the content of the LoggingEvent
134 * in a format compatible with log4j's serialized form.
135 */
136 void write(helpers::ObjectOutputStream& os, helpers::Pool& p) const;
137
138 /**
139 * Appends the the context corresponding to the <code>key</code> parameter.
140 * If there is a local MDC copy, possibly because we are in a logging
141 * server or running inside AsyncAppender, then we search for the key in
142 * MDC copy, if a value is found it is returned. Otherwise, if the search
143 * in MDC copy returns an empty result, then the current thread's
144 * <code>MDC</code> is used.
145 *
146 * <p>
147 * Note that <em>both</em> the local MDC copy and the current thread's MDC
148 * are searched.
149 * </p>
150 * @param key key.
151 * @param dest string to which value, if any, is appended.
152 * @return true if key had a corresponding value.
153 */
154 bool getMDC(const LogString& key, LogString& dest) const;
155
156 /**
157 * Returns the set of of the key values in the MDC for the event.
158 * The returned set is unmodifiable by the caller.
159 *
160 * @return Set an unmodifiable set of the MDC keys.
161 *
162 */
163 KeySet getMDCKeySet() const;
164
165 /**
166 Obtain a copy of this thread's MDC prior to serialization
167 or asynchronous logging.
168 */
169 void getMDCCopy() const;
170
171 /**
172 * Return a previously set property.
173 * @param key key.
174 * @param dest string to which value, if any, is appended.
175 * @return true if key had a corresponding value.
176 */
177 bool getProperty(const LogString& key, LogString& dest) const;
178 /**
179 * Returns the set of of the key values in the properties
180 * for the event. The returned set is unmodifiable by the caller.
181 *
182 * @return Set an unmodifiable set of the property keys.
183 */
184 KeySet getPropertyKeySet() const;
185
186 /**
187 * Set a string property using a key and a string value. since 1.3
188 */
189 void setProperty(const LogString& key, const LogString& value);
190
191 private:
192 /**
193 * The logger of the logging event.
194 **/
195 LogString logger;
196
197 /** level of logging event. */
198 LevelPtr level;
199
200 /** The nested diagnostic context (NDC) of logging event. */
201 mutable LogString* ndc;
202
203 /** The mapped diagnostic context (MDC) of logging event. */
204 mutable MDC::Map* mdcCopy;
205
206 /**
207 * A map of String keys and String values.
208 */
209 std::map<LogString, LogString> * properties;
210
211 /** Have we tried to do an NDC lookup? If we did, there is no need
212 * to do it again. Note that its value is always false when
213 * serialized. Thus, a receiving SocketNode will never use it's own
214 * (incorrect) NDC. See also writeObject method.
215 */
216 mutable bool ndcLookupRequired;
217
218 /**
219 * Have we tried to do an MDC lookup? If we did, there is no need to do it
220 * again. Note that its value is always false when serialized. See also
221 * the getMDC and getMDCCopy methods.
222 */
223 mutable bool mdcCopyLookupRequired;
224
225 /** The application supplied message of logging event. */
226 LogString message;
227
228
229 /** The number of milliseconds elapsed from 1/1/1970 until logging event
230 was created. */
231 log4cxx_time_t timeStamp;
232
233 /** The is the location where this log statement was written. */
234 const log4cxx::spi::LocationInfo locationInfo;
235
236
237 /** The identifier of thread in which this logging event
238 was generated.
239 */
240 const LogString threadName;
241
242 //
243 // prevent copy and assignment
244 //
245 LoggingEvent(const LoggingEvent&);
246 LoggingEvent& operator=(const LoggingEvent&);
247 static const LogString getCurrentThreadName();
248
249 static void writeProlog(log4cxx::helpers::ObjectOutputStream& os, log4cxx::helpers::Pool& p);
250
251 };
252
253 LOG4CXX_PTR_DEF(LoggingEvent);
254 LOG4CXX_LIST_DEF(LoggingEventList, LoggingEventPtr);
255 }
256}
257
258#if defined(_MSC_VER)
259#pragma warning (pop)
260#endif
261
262
263#endif //_LOG4CXX_SPI_LOGGING_EVENT_H
Note: See TracBrowser for help on using the repository browser.