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 
66  LoggingEvent();
67 
79  LoggingEvent(const LogString& logger,
80  const LevelPtr& level, const LogString& message,
81  const log4cxx::spi::LocationInfo& location);
82 
83  ~LoggingEvent();
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 
148  void write(helpers::ObjectOutputStream& os, helpers::Pool& p) const;
149 
166  bool getMDC(const LogString& key, LogString& dest) const;
167 
175  KeySet getMDCKeySet() const;
176 
181  void getMDCCopy() const;
182 
189  bool getProperty(const LogString& key, LogString& dest) const;
196  KeySet getPropertyKeySet() 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 
266 LOG4CXX_LIST_DEF(LoggingEventList, LoggingEventPtr);
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
#define LOG4CXX_CAST_ENTRY(Interface)
Definition: object.h:148
#define END_LOG4CXX_CAST_MAP()
Definition: object.h:142
std::shared_ptr< Level > LevelPtr
Definition: optionconverter.h:27
LOG4CXX_PTR_DEF(AppenderAttachableImpl)
std::shared_ptr< LoggingEvent > LoggingEventPtr
Definition: appender.h:37
The internal representation of logging events.
Definition: loggingevent.h:53
#define BEGIN_LOG4CXX_CAST_MAP()
Definition: object.h:136
const LogString & getLoggerName() const
Return the name of the logger.
Definition: loggingevent.h:92
LOG4CXX_LIST_DEF(ByteList, unsigned char)
const LogString & getRenderedMessage() const
Return the message for this logging event.
Definition: loggingevent.h:104
log4cxx_time_t getTimeStamp() const
The number of microseconds elapsed from 01.01.1970 until logging event was created.
Definition: loggingevent.h:122
#define DECLARE_LOG4CXX_OBJECT(object)
Definition: object.h:39
Emulates java serialization.
Definition: objectoutputstream.h:33
const LogString & getThreadName() const
Return the threadName of this event.
Definition: loggingevent.h:115
base class for java-like objects.
Definition: object.h:101
Definition: pool.h:32
This class represents the location of a logging statement.
Definition: locationinfo.h:33
spi::KeySet KeySet
Definition: loggingevent.h:62
Definition: appender.h:32
std::basic_string< logchar > LogString
Definition: logstring.h:66
const LogString & getMessage() const
Return the message for this logging event.
Definition: loggingevent.h:98
const log4cxx::spi::LocationInfo & getLocationInformation() const
Definition: loggingevent.h:128