Apache log4cxx  Version 0.13.0
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 
124  const LogString& getThreadUserName() const;
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 
154  void write(helpers::ObjectOutputStream& os, helpers::Pool& p) const;
155 
172  bool getMDC(const LogString& key, LogString& dest) const;
173 
181  KeySet getMDCKeySet() const;
182 
187  void getMDCCopy() const;
188 
195  bool getProperty(const LogString& key, LogString& dest) const;
202  KeySet getPropertyKeySet() 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  //
272  LoggingEvent(const LoggingEvent&);
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 
282 LOG4CXX_LIST_DEF(LoggingEventList, LoggingEventPtr);
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
#define LOG4CXX_CAST_ENTRY(Interface)
Definition: object.h:153
#define END_LOG4CXX_CAST_MAP()
Definition: object.h:147
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:141
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:128
#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:46
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:134