Apache log4cxx Version 0.13.0
Loading...
Searching...
No Matches
loggingevent.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_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#include <log4cxx/logstring.h>
27#include <time.h>
28#include <log4cxx/logger.h>
29#include <log4cxx/mdc.h>
31#include <vector>
32
33
34namespace log4cxx
35{
36namespace helpers
37{
38class ObjectOutputStream;
39}
40
41namespace spi
42{
44
53class LOG4CXX_EXPORT LoggingEvent :
54 public virtual helpers::Object
55{
56 public:
61
62 typedef spi::KeySet KeySet;
63
67
79 LoggingEvent(const LogString& logger,
80 const LevelPtr& level, const LogString& message,
81 const log4cxx::spi::LocationInfo& location);
82
84
86 inline const LevelPtr& getLevel() const
87 {
88 return level;
89 }
90
92 inline const LogString& getLoggerName() const
93 {
94 return logger;
95 }
96
98 inline const LogString& getMessage() const
99 {
100 return message;
101 }
102
104 inline const LogString& getRenderedMessage() const
105 {
106 return message;
107 }
108
112 static log4cxx_time_t getStartTime();
113
115 inline const LogString& getThreadName() const
116 {
117 return threadName;
118 }
119
125
128 inline log4cxx_time_t getTimeStamp() const
129 {
130 return timeStamp;
131 }
132
133 /* Return the file where this log statement was written. */
135 {
136 return locationInfo;
137 }
138
148 bool getNDC(LogString& dest) const;
149
155
172 bool getMDC(const LogString& key, LogString& dest) const;
173
182
187 void getMDCCopy() const;
188
195 bool getProperty(const LogString& key, LogString& dest) const;
203
207 void setProperty(const LogString& key, const LogString& value);
208
209 private:
213 LogString logger;
214
216 LevelPtr level;
217
219 mutable LogString* ndc;
220
222 mutable MDC::Map* mdcCopy;
223
227 std::map<LogString, LogString>* properties;
228
234 mutable bool ndcLookupRequired;
235
241 mutable bool mdcCopyLookupRequired;
242
244 LogString message;
245
246
249 log4cxx_time_t timeStamp;
250
252 const log4cxx::spi::LocationInfo locationInfo;
253
254
260 const LogString threadName;
261
267 const LogString threadUserName;
268
269 //
270 // prevent copy and assignment
271 //
273 LoggingEvent& operator=(const LoggingEvent&);
274 static const LogString getCurrentThreadName();
275 static const LogString getCurrentThreadUserName();
276
277 static void writeProlog(log4cxx::helpers::ObjectOutputStream& os, log4cxx::helpers::Pool& p);
278
279};
280
283}
284}
285
286#if defined(_MSC_VER)
287 #pragma warning (pop)
288#endif
289
290
291#endif //_LOG4CXX_SPI_LOGGING_EVENT_H
std::map< LogString, LogString > Map
String to string stl map.
Definition: mdc.h:46
Emulates java serialization.
Definition: objectoutputstream.h:34
base class for java-like objects.
Definition: object.h:102
Definition: pool.h:33
This class represents the location of a logging statement.
Definition: locationinfo.h:47
The internal representation of logging events.
Definition: loggingevent.h:55
const LogString & getMessage() const
Return the message for this logging event.
Definition: loggingevent.h:98
log4cxx_time_t getTimeStamp() const
The number of microseconds elapsed from 01.01.1970 until logging event was created.
Definition: loggingevent.h:128
bool getMDC(const LogString &key, LogString &dest) const
Appends the the context corresponding to the key parameter.
bool getNDC(LogString &dest) const
This method appends the NDC for this event to passed string.
const LogString & getLoggerName() const
Return the name of the logger.
Definition: loggingevent.h:92
KeySet getPropertyKeySet() const
Returns the set of of the key values in the properties for the event.
void getMDCCopy() const
Obtain a copy of this thread's MDC prior to serialization or asynchronous logging.
void setProperty(const LogString &key, const LogString &value)
Set a string property using a key and a string value.
static log4cxx_time_t getStartTime()
Returns the time when the application started, in microseconds elapsed since 01.01....
spi::KeySet KeySet
Definition: loggingevent.h:62
void write(helpers::ObjectOutputStream &os, helpers::Pool &p) const
Writes the content of the LoggingEvent in a format compatible with log4j's serialized form.
KeySet getMDCKeySet() const
Returns the set of of the key values in the MDC for the event.
bool getProperty(const LogString &key, LogString &dest) const
Return a previously set property.
const LogString & getRenderedMessage() const
Return the message for this logging event.
Definition: loggingevent.h:104
const LogString & getThreadName() const
Return the threadName of this event.
Definition: loggingevent.h:115
const LogString & getThreadUserName() const
Get the user name of the thread.
const log4cxx::spi::LocationInfo & getLocationInformation() const
Definition: loggingevent.h:134
LOG4CXX_PTR_DEF(LoggerRepository)
LOG4CXX_LIST_DEF(HierarchyEventListenerList, HierarchyEventListenerPtr)
std::shared_ptr< LoggingEvent > LoggingEventPtr
Definition: appender.h:38
Definition: messagehandler.h:23
std::basic_string< logchar > LogString
Definition: logstring.h:66
std::shared_ptr< Level > LevelPtr
Definition: optionconverter.h:28
#define LOG4CXX_CAST_ENTRY(Interface)
Definition: object.h:153
#define END_LOG4CXX_CAST_MAP()
Definition: object.h:147
#define DECLARE_LOG4CXX_OBJECT(object)
Definition: object.h:39
#define BEGIN_LOG4CXX_CAST_MAP()
Definition: object.h:141