log4cplus
2.0.0
|
00001 // -*- C++ -*- 00002 // Module: Log4CPLUS 00003 // File: loggingevent.h 00004 // Created: 6/2001 00005 // Author: Tad E. Smith 00006 // 00007 // 00008 // Copyright 2001-2015 Tad E. Smith 00009 // 00010 // Licensed under the Apache License, Version 2.0 (the "License"); 00011 // you may not use this file except in compliance with the License. 00012 // You may obtain a copy of the License at 00013 // 00014 // http://www.apache.org/licenses/LICENSE-2.0 00015 // 00016 // Unless required by applicable law or agreed to in writing, software 00017 // distributed under the License is distributed on an "AS IS" BASIS, 00018 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00019 // See the License for the specific language governing permissions and 00020 // limitations under the License. 00021 00024 #ifndef LOG4CPLUS_SPI_INTERNAL_LOGGING_EVENT_HEADER_ 00025 #define LOG4CPLUS_SPI_INTERNAL_LOGGING_EVENT_HEADER_ 00026 00027 #include <log4cplus/config.hxx> 00028 00029 #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE) 00030 #pragma once 00031 #endif 00032 00033 #include <memory> 00034 #include <log4cplus/loglevel.h> 00035 #include <log4cplus/ndc.h> 00036 #include <log4cplus/mdc.h> 00037 #include <log4cplus/tstring.h> 00038 #include <log4cplus/helpers/timehelper.h> 00039 #include <log4cplus/thread/threads.h> 00040 00041 namespace log4cplus { 00042 namespace spi { 00051 class LOG4CPLUS_EXPORT InternalLoggingEvent { 00052 public: 00053 // Ctors 00066 InternalLoggingEvent(const log4cplus::tstring& logger, 00067 LogLevel loglevel, const log4cplus::tstring& message, 00068 const char* filename, int line, const char * function = nullptr); 00069 00070 InternalLoggingEvent(const log4cplus::tstring& logger, 00071 LogLevel loglevel, const log4cplus::tstring& ndc, 00072 MappedDiagnosticContextMap const & mdc, 00073 const log4cplus::tstring& message, 00074 const log4cplus::tstring& thread, 00075 log4cplus::helpers::Time time, const log4cplus::tstring& file, 00076 int line, const log4cplus::tstring & function 00077 = log4cplus::tstring ()); 00078 00079 InternalLoggingEvent (); 00080 00081 InternalLoggingEvent( 00082 const log4cplus::spi::InternalLoggingEvent& rhs); 00083 00084 virtual ~InternalLoggingEvent(); 00085 00086 void setLoggingEvent (const log4cplus::tstring & logger, 00087 LogLevel ll, const log4cplus::tstring & message, 00088 const char * filename, int line, 00089 const char * function = nullptr); 00090 00091 void setFunction (char const * func); 00092 void setFunction (log4cplus::tstring const &); 00093 00094 00095 // public virtual methods 00097 virtual const log4cplus::tstring& getMessage() const; 00098 00103 virtual unsigned int getType() const; 00104 00108 virtual std::unique_ptr<InternalLoggingEvent> clone() const; 00109 00110 00111 // public methods 00115 const log4cplus::tstring& getLoggerName() const 00116 { 00117 return loggerName; 00118 } 00119 00121 LogLevel getLogLevel() const 00122 { 00123 return ll; 00124 } 00125 00127 const log4cplus::tstring& getNDC() const 00128 { 00129 if (!ndcCached) 00130 { 00131 ndc = log4cplus::getNDC().get(); 00132 ndcCached = true; 00133 } 00134 return ndc; 00135 } 00136 00137 MappedDiagnosticContextMap const & getMDCCopy () const 00138 { 00139 if (!mdcCached) 00140 { 00141 mdc = log4cplus::getMDC().getContext (); 00142 mdcCached = true; 00143 } 00144 return mdc; 00145 } 00146 00147 tstring const & getMDC (tstring const & key) const; 00148 00150 const log4cplus::tstring& getThread() const 00151 { 00152 if (! threadCached) 00153 { 00154 thread = thread::getCurrentThreadName (); 00155 threadCached = true; 00156 } 00157 return thread; 00158 } 00159 00162 const log4cplus::tstring& getThread2() const 00163 { 00164 if (! thread2Cached) 00165 { 00166 thread2 = thread::getCurrentThreadName2 (); 00167 thread2Cached = true; 00168 } 00169 return thread2; 00170 } 00171 00172 00174 const log4cplus::helpers::Time& getTimestamp() const 00175 { 00176 return timestamp; 00177 } 00178 00180 const log4cplus::tstring& getFile() const 00181 { 00182 return file; 00183 } 00184 00186 int getLine() const { return line; } 00187 00188 log4cplus::tstring const & getFunction () const 00189 { 00190 return function; 00191 } 00192 00193 void gatherThreadSpecificData () const; 00194 00195 void swap (InternalLoggingEvent &); 00196 00197 // public operators 00198 log4cplus::spi::InternalLoggingEvent& 00199 operator=(const log4cplus::spi::InternalLoggingEvent& rhs); 00200 00201 // static methods 00202 static unsigned int getDefaultType(); 00203 00204 protected: 00205 // Data 00206 log4cplus::tstring message; 00207 log4cplus::tstring loggerName; 00208 LogLevel ll; 00209 mutable log4cplus::tstring ndc; 00210 mutable MappedDiagnosticContextMap mdc; 00211 mutable log4cplus::tstring thread; 00212 mutable log4cplus::tstring thread2; 00213 log4cplus::helpers::Time timestamp; 00214 log4cplus::tstring file; 00215 log4cplus::tstring function; 00216 int line; 00218 mutable bool threadCached; 00219 mutable bool thread2Cached; 00221 mutable bool ndcCached; 00223 mutable bool mdcCached; 00224 }; 00225 00226 } // end namespace spi 00227 } // end namespace log4cplus 00228 00229 #endif // LOG4CPLUS_SPI_INTERNAL_LOGGING_EVENT_HEADER_