Apache log4cxx  Version 0.12.1
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 
34 namespace log4cxx
35 {
36 namespace helpers
37 {
38 class ObjectOutputStream;
39 }
40 
41 namespace spi
42 {
44 
53 class 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 
122  inline log4cxx_time_t getTimeStamp() const
123  {
124  return timeStamp;
125  }
126 
127  /* Return the file where this log statement was written. */
129  {
130  return locationInfo;
131  }
132 
142  bool getNDC(LogString& dest) const;
143 
149 
166  bool getMDC(const LogString& key, LogString& dest) const;
167 
176 
181  void getMDCCopy() const;
182 
189  bool getProperty(const LogString& key, LogString& dest) const;
197 
201  void setProperty(const LogString& key, const LogString& value);
202 
203  private:
207  LogString logger;
208 
210  LevelPtr level;
211 
213  mutable LogString* ndc;
214 
216  mutable MDC::Map* mdcCopy;
217 
221  std::map<LogString, LogString>* properties;
222 
228  mutable bool ndcLookupRequired;
229 
235  mutable bool mdcCopyLookupRequired;
236 
238  LogString message;
239 
240 
243  log4cxx_time_t timeStamp;
244 
246  const log4cxx::spi::LocationInfo locationInfo;
247 
248 
252  const LogString threadName;
253 
254  //
255  // prevent copy and assignment
256  //
257  LoggingEvent(const LoggingEvent&);
258  LoggingEvent& operator=(const LoggingEvent&);
259  static const LogString getCurrentThreadName();
260 
261  static void writeProlog(log4cxx::helpers::ObjectOutputStream& os, log4cxx::helpers::Pool& p);
262 
263 };
264 
267 }
268 }
269 
270 #if defined(_MSC_VER)
271  #pragma warning (pop)
272 #endif
273 
274 
275 #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:34
The internal representation of logging events.
Definition: loggingevent.h:55
const LogString & getThreadName() const
Return the threadName of this event.
Definition: loggingevent.h:115
log4cxx_time_t getTimeStamp() const
The number of microseconds elapsed from 01.01.1970 until logging event was created.
Definition: loggingevent.h:122
const LogString & getMessage() const
Return the message for this logging event.
Definition: loggingevent.h:98
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.
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.
const log4cxx::spi::LocationInfo & getLocationInformation() const
Definition: loggingevent.h:128
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 & getLoggerName() const
Return the name of the logger.
Definition: loggingevent.h:92
LOG4CXX_PTR_DEF(LoggerRepository)
LOG4CXX_LIST_DEF(HierarchyEventListenerList, HierarchyEventListenerPtr)
std::shared_ptr< LoggingEvent > LoggingEventPtr
Definition: appender.h:37
Definition: appender.h:33
std::basic_string< logchar > LogString
Definition: logstring.h:66
std::shared_ptr< Level > LevelPtr
Definition: optionconverter.h:27
#define LOG4CXX_CAST_ENTRY(Interface)
Definition: object.h:148
#define END_LOG4CXX_CAST_MAP()
Definition: object.h:142
#define DECLARE_LOG4CXX_OBJECT(object)
Definition: object.h:39
#define BEGIN_LOG4CXX_CAST_MAP()
Definition: object.h:136