Apache log4cxx  Version 0.11.0
loggingevent.h
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 
37 namespace log4cxx
38 {
39 namespace helpers
40 {
41 class ObjectOutputStream;
42 }
43 
44 namespace spi
45 {
46 LOG4CXX_LIST_DEF(KeySet, LogString);
47 
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  typedef spi::KeySet KeySet;
66 
69  LoggingEvent();
70 
82  LoggingEvent(const LogString& logger,
83  const LevelPtr& level, const LogString& message,
84  const log4cxx::spi::LocationInfo& location);
85 
86  ~LoggingEvent();
87 
89  inline const LevelPtr& getLevel() const
90  {
91  return level;
92  }
93 
95  inline const LogString& getLoggerName() const
96  {
97  return logger;
98  }
99 
101  inline const LogString& getMessage() const
102  {
103  return message;
104  }
105 
107  inline const LogString& getRenderedMessage() const
108  {
109  return message;
110  }
111 
115  static log4cxx_time_t getStartTime();
116 
118  inline const LogString& getThreadName() const
119  {
120  return threadName;
121  }
122 
125  inline log4cxx_time_t getTimeStamp() const
126  {
127  return timeStamp;
128  }
129 
130  /* Return the file where this log statement was written. */
131  inline const log4cxx::spi::LocationInfo& getLocationInformation() const
132  {
133  return locationInfo;
134  }
135 
145  bool getNDC(LogString& dest) const;
146 
151  void write(helpers::ObjectOutputStream& os, helpers::Pool& p) const;
152 
169  bool getMDC(const LogString& key, LogString& dest) const;
170 
178  KeySet getMDCKeySet() const;
179 
184  void getMDCCopy() const;
185 
192  bool getProperty(const LogString& key, LogString& dest) const;
199  KeySet getPropertyKeySet() const;
200 
204  void setProperty(const LogString& key, const LogString& value);
205 
206  private:
210  LogString logger;
211 
213  LevelPtr level;
214 
216  mutable LogString* ndc;
217 
219  mutable MDC::Map* mdcCopy;
220 
224  std::map<LogString, LogString>* properties;
225 
231  mutable bool ndcLookupRequired;
232 
238  mutable bool mdcCopyLookupRequired;
239 
241  LogString message;
242 
243 
246  log4cxx_time_t timeStamp;
247 
249  const log4cxx::spi::LocationInfo locationInfo;
250 
251 
255  const LogString threadName;
256 
257  //
258  // prevent copy and assignment
259  //
260  LoggingEvent(const LoggingEvent&);
261  LoggingEvent& operator=(const LoggingEvent&);
262  static const LogString getCurrentThreadName();
263 
264  static void writeProlog(log4cxx::helpers::ObjectOutputStream& os, log4cxx::helpers::Pool& p);
265 
266 };
267 
268 LOG4CXX_PTR_DEF(LoggingEvent);
269 LOG4CXX_LIST_DEF(LoggingEventList, LoggingEventPtr);
270 }
271 }
272 
273 #if defined(_MSC_VER)
274  #pragma warning (pop)
275 #endif
276 
277 
278 #endif //_LOG4CXX_SPI_LOGGING_EVENT_H
std::map< LogString, LogString > Map
String to string stl map.
Definition: mdc.h:46
const LevelPtr & getLevel() const
Return the level of this event.
Definition: loggingevent.h:89
The internal representation of logging events.
Definition: loggingevent.h:56
const LogString & getLoggerName() const
Return the name of the logger.
Definition: loggingevent.h:95
const LogString & getRenderedMessage() const
Return the message for this logging event.
Definition: loggingevent.h:107
log4cxx_time_t getTimeStamp() const
The number of microseconds elapsed from 01.01.1970 until logging event was created.
Definition: loggingevent.h:125
Implementation class for Object.
Definition: objectimpl.h:28
Emulates java serialization.
Definition: objectoutputstream.h:33
const LogString & getThreadName() const
Return the threadName of this event.
Definition: loggingevent.h:118
Definition: pool.h:32
This class represents the location of a logging statement.
Definition: locationinfo.h:33
Definition: appender.h:33
const LogString & getMessage() const
Return the message for this logging event.
Definition: loggingevent.h:101