log4cplus  2.0.5
loggingevent.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 // Module: Log4CPLUS
3 // File: loggingevent.h
4 // Created: 6/2001
5 // Author: Tad E. Smith
6 //
7 //
8 // Copyright 2001-2017 Tad E. Smith
9 //
10 // Licensed under the Apache License, Version 2.0 (the "License");
11 // you may not use this file except in compliance with the License.
12 // You may obtain a copy of the License at
13 //
14 // http://www.apache.org/licenses/LICENSE-2.0
15 //
16 // Unless required by applicable law or agreed to in writing, software
17 // distributed under the License is distributed on an "AS IS" BASIS,
18 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 // See the License for the specific language governing permissions and
20 // limitations under the License.
21 
24 #ifndef LOG4CPLUS_SPI_INTERNAL_LOGGING_EVENT_HEADER_
25 #define LOG4CPLUS_SPI_INTERNAL_LOGGING_EVENT_HEADER_
26 
27 #include <log4cplus/config.hxx>
28 
29 #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE)
30 #pragma once
31 #endif
32 
33 #include <memory>
34 #include <log4cplus/loglevel.h>
35 #include <log4cplus/ndc.h>
36 #include <log4cplus/mdc.h>
37 #include <log4cplus/tstring.h>
40 
41 namespace log4cplus {
42  namespace spi {
52  public:
53  // Ctors
67  LogLevel loglevel, const log4cplus::tstring& message,
68  const char* filename, int line, const char * function = nullptr);
69 
71  LogLevel loglevel, const log4cplus::tstring& ndc,
72  MappedDiagnosticContextMap const & mdc,
73  const log4cplus::tstring& message,
74  const log4cplus::tstring& thread,
76  int line, const log4cplus::tstring & function
78 
80  LogLevel loglevel, const log4cplus::tstring& ndc,
81  MappedDiagnosticContextMap const & mdc,
82  const log4cplus::tstring& message,
83  const log4cplus::tstring& thread,
84  const log4cplus::tstring& thread2,
85  log4cplus::helpers::Time time, const log4cplus::tstring& file,
86  int line, const log4cplus::tstring & function
87  = log4cplus::tstring ());
88 
90 
92  const log4cplus::spi::InternalLoggingEvent& rhs);
93 
95 
96  void setLoggingEvent (const log4cplus::tstring & logger,
97  LogLevel ll, const log4cplus::tstring & message,
98  const char * filename, int line,
99  const char * function = nullptr);
100 
101  void setFunction (char const * func);
102  void setFunction (log4cplus::tstring const &);
103 
104 
105  // public virtual methods
107  virtual const log4cplus::tstring& getMessage() const;
108 
113  virtual unsigned int getType() const;
114 
118  virtual std::unique_ptr<InternalLoggingEvent> clone() const;
119 
120 
121  // public methods
125  const log4cplus::tstring& getLoggerName() const
126  {
127  return loggerName;
128  }
129 
132  {
133  return ll;
134  }
135 
137  const log4cplus::tstring& getNDC() const
138  {
139  if (!ndcCached)
140  {
141  ndc = log4cplus::getNDC().get();
142  ndcCached = true;
143  }
144  return ndc;
145  }
146 
148  {
149  if (!mdcCached)
150  {
151  mdc = log4cplus::getMDC().getContext ();
152  mdcCached = true;
153  }
154  return mdc;
155  }
156 
157  tstring const & getMDC (tstring const & key) const;
158 
161  {
162  if (! threadCached)
163  {
164  thread = thread::getCurrentThreadName ();
165  threadCached = true;
166  }
167  return thread;
168  }
169 
173  {
174  if (! thread2Cached)
175  {
176  thread2 = thread::getCurrentThreadName2 ();
177  thread2Cached = true;
178  }
179  return thread2;
180  }
181 
182 
185  {
186  return timestamp;
187  }
188 
191  {
192  return file;
193  }
194 
196  int getLine() const { return line; }
197 
199  {
200  return function;
201  }
202 
204 
206 
207  // public operators
210 
211  // static methods
212  static unsigned int getDefaultType();
213 
214  protected:
215  // Data
226  int line;
228  mutable bool threadCached;
229  mutable bool thread2Cached;
231  mutable bool ndcCached;
233  mutable bool mdcCached;
234  };
235 
236  } // end namespace spi
237 } // end namespace log4cplus
238 
239 #endif // LOG4CPLUS_SPI_INTERNAL_LOGGING_EVENT_HEADER_
tstring.h
log4cplus::spi::InternalLoggingEvent::file
log4cplus::tstring file
Definition: loggingevent.h:224
log4cplus::spi::InternalLoggingEvent::swap
void swap(InternalLoggingEvent &)
timehelper.h
log4cplus
Definition: appender.h:46
log4cplus::spi::InternalLoggingEvent::getNDC
const log4cplus::tstring & getNDC() const
The nested diagnostic context (NDC) of logging event.
Definition: loggingevent.h:137
log4cplus::getMDC
LOG4CPLUS_EXPORT MDC & getMDC()
log4cplus::tstring
std::basic_string< tchar > tstring
Definition: tstring.h:39
log4cplus::spi::InternalLoggingEvent::getMDC
tstring const & getMDC(tstring const &key) const
threads.h
log4cplus::spi::InternalLoggingEvent::timestamp
log4cplus::helpers::Time timestamp
Definition: loggingevent.h:223
log4cplus::spi::InternalLoggingEvent::ndcCached
bool ndcCached
Indicates whether or not the NDC has been retrieved.
Definition: loggingevent.h:231
log4cplus::spi::InternalLoggingEvent::getDefaultType
static unsigned int getDefaultType()
log4cplus::spi::InternalLoggingEvent::InternalLoggingEvent
InternalLoggingEvent(const log4cplus::tstring &logger, LogLevel loglevel, const log4cplus::tstring &message, const char *filename, int line, const char *function=nullptr)
Instantiate a LoggingEvent from the supplied parameters.
loglevel.h
This header defines the LogLevel type.
log4cplus::spi::InternalLoggingEvent::message
log4cplus::tstring message
Definition: loggingevent.h:216
log4cplus::spi::InternalLoggingEvent::line
int line
Definition: loggingevent.h:226
log4cplus::spi::InternalLoggingEvent::mdcCached
bool mdcCached
Indicates whether or not the MDC has been retrieved.
Definition: loggingevent.h:233
log4cplus::thread::getCurrentThreadName
LOG4CPLUS_EXPORT log4cplus::tstring const & getCurrentThreadName()
log4cplus::spi::InternalLoggingEvent::ll
LogLevel ll
Definition: loggingevent.h:218
log4cplus::spi::InternalLoggingEvent::loggerName
log4cplus::tstring loggerName
Definition: loggingevent.h:217
log4cplus::spi::InternalLoggingEvent::getLogLevel
LogLevel getLogLevel() const
LogLevel of logging event.
Definition: loggingevent.h:131
log4cplus::spi::InternalLoggingEvent::thread
log4cplus::tstring thread
Definition: loggingevent.h:221
log4cplus::MDC::getContext
MappedDiagnosticContextMap const & getContext() const
config.hxx
LOG4CPLUS_ATTRIBUTE_DEPRECATED
#define LOG4CPLUS_ATTRIBUTE_DEPRECATED
Definition: config.hxx:136
log4cplus::spi::InternalLoggingEvent::getMDCCopy
MappedDiagnosticContextMap const & getMDCCopy() const
Definition: loggingevent.h:147
mdc.h
log4cplus::spi::InternalLoggingEvent::getThread
const log4cplus::tstring & getThread() const
The name of thread in which this logging event was generated.
Definition: loggingevent.h:160
log4cplus::LogLevel
int LogLevel
Defines the minimum set of priorities recognized by the system, that is FATAL_LOG_LEVEL,...
Definition: loglevel.h:48
log4cplus::spi::InternalLoggingEvent::getFile
const log4cplus::tstring & getFile() const
The is the file where this log statement was written.
Definition: loggingevent.h:190
log4cplus::spi::InternalLoggingEvent::getTimestamp
const log4cplus::helpers::Time & getTimestamp() const
Time stamp when the event was created.
Definition: loggingevent.h:184
log4cplus::spi::InternalLoggingEvent::operator=
log4cplus::spi::InternalLoggingEvent & operator=(const log4cplus::spi::InternalLoggingEvent &rhs)
log4cplus::thread::getCurrentThreadName2
LOG4CPLUS_EXPORT log4cplus::tstring const & getCurrentThreadName2()
log4cplus::spi::InternalLoggingEvent
The internal representation of logging events.
Definition: loggingevent.h:51
log4cplus::spi::InternalLoggingEvent::mdc
MappedDiagnosticContextMap mdc
Definition: loggingevent.h:220
log4cplus::spi::InternalLoggingEvent::ndc
log4cplus::tstring ndc
Definition: loggingevent.h:219
LOG4CPLUS_EXPORT
#define LOG4CPLUS_EXPORT
Definition: win32.h:141
log4cplus::spi::InternalLoggingEvent::gatherThreadSpecificData
void gatherThreadSpecificData() const
log4cplus::MappedDiagnosticContextMap
std::map< tstring, tstring > MappedDiagnosticContextMap
Definition: mdc.h:43
ndc.h
This header defined the NDC class.
log4cplus::spi::InternalLoggingEvent::getFunction
log4cplus::tstring const & getFunction() const
Definition: loggingevent.h:198
log4cplus::NDC::get
log4cplus::tstring const & get() const
Used when printing the diagnostic context.
log4cplus::spi::InternalLoggingEvent::getLine
int getLine() const
The is the line where this log statement was written.
Definition: loggingevent.h:196
log4cplus::helpers::Time
chrono::time_point< Clock, Duration > Time
Definition: timehelper.h:54
log4cplus::spi::InternalLoggingEvent::thread2Cached
bool thread2Cached
Definition: loggingevent.h:229
log4cplus::spi::InternalLoggingEvent::thread2
log4cplus::tstring thread2
Definition: loggingevent.h:222
log4cplus::spi::InternalLoggingEvent::InternalLoggingEvent
InternalLoggingEvent(const log4cplus::tstring &logger, LogLevel loglevel, const log4cplus::tstring &ndc, MappedDiagnosticContextMap const &mdc, const log4cplus::tstring &message, const log4cplus::tstring &thread, log4cplus::helpers::Time time, const log4cplus::tstring &file, int line, const log4cplus::tstring &function=log4cplus::tstring()) LOG4CPLUS_ATTRIBUTE_DEPRECATED
log4cplus::spi::InternalLoggingEvent::getThread2
const log4cplus::tstring & getThread2() const
The alternative name of thread in which this logging event was generated.
Definition: loggingevent.h:172
log4cplus::getNDC
LOG4CPLUS_EXPORT NDC & getNDC()
Return a reference to the singleton object.
log4cplus::spi::InternalLoggingEvent::threadCached
bool threadCached
Indicates whether or not the Threadname has been retrieved.
Definition: loggingevent.h:228