log4cplus  2.1.0
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_
MappedDiagnosticContextMap const & getContext() const
log4cplus::tstring const & get() const
Used when printing the diagnostic context.
The internal representation of logging events.
Definition: loggingevent.h:51
const log4cplus::tstring & getThread2() const
The alternative name of thread in which this logging event was generated.
Definition: loggingevent.h:172
tstring const & getMDC(tstring const &key) const
const log4cplus::tstring & getThread() const
The name of thread in which this logging event was generated.
Definition: loggingevent.h:160
const log4cplus::helpers::Time & getTimestamp() const
Time stamp when the event was created.
Definition: loggingevent.h:184
bool mdcCached
Indicates whether or not the MDC has been retrieved.
Definition: loggingevent.h:233
bool threadCached
Indicates whether or not the Threadname has been retrieved.
Definition: loggingevent.h:228
log4cplus::tstring const & getFunction() const
Definition: loggingevent.h:198
MappedDiagnosticContextMap mdc
Definition: loggingevent.h:220
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::helpers::Time timestamp
Definition: loggingevent.h:223
void swap(InternalLoggingEvent &)
int getLine() const
The is the line where this log statement was written.
Definition: loggingevent.h:196
const log4cplus::tstring & getFile() const
The is the file where this log statement was written.
Definition: loggingevent.h:190
log4cplus::spi::InternalLoggingEvent & operator=(const log4cplus::spi::InternalLoggingEvent &rhs)
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 getLogLevel() const
LogLevel of logging event.
Definition: loggingevent.h:131
const log4cplus::tstring & getNDC() const
The nested diagnostic context (NDC) of logging event.
Definition: loggingevent.h:137
bool ndcCached
Indicates whether or not the NDC has been retrieved.
Definition: loggingevent.h:231
MappedDiagnosticContextMap const & getMDCCopy() const
Definition: loggingevent.h:147
static unsigned int getDefaultType()
#define LOG4CPLUS_ATTRIBUTE_DEPRECATED
Definition: config.hxx:136
This header defines the LogLevel type.
chrono::time_point< Clock, Duration > Time
Definition: timehelper.h:54
LOG4CPLUS_EXPORT log4cplus::tstring const & getCurrentThreadName()
LOG4CPLUS_EXPORT log4cplus::tstring const & getCurrentThreadName2()
LOG4CPLUS_EXPORT NDC & getNDC()
Return a reference to the singleton object.
std::basic_string< tchar > tstring
Definition: tstring.h:39
std::map< tstring, tstring > MappedDiagnosticContextMap
Definition: mdc.h:43
int LogLevel
Defines the minimum set of priorities recognized by the system, that is FATAL_LOG_LEVEL,...
Definition: loglevel.h:48
LOG4CPLUS_EXPORT MDC & getMDC()
This header defined the NDC class.
#define LOG4CPLUS_EXPORT
Definition: win32.h:141