log4cplus  1.1.0
loggingevent.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 // Module:  Log4CPLUS
00003 // File:    loggingevent.h
00004 // Created: 6/2001
00005 // Author:  Tad E. Smith
00006 //
00007 //
00008 // Copyright 2001-2010 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
00065             InternalLoggingEvent(const log4cplus::tstring& logger,
00066                 LogLevel loglevel, const log4cplus::tstring& message,
00067                 const char* filename, int line);
00068 
00069             InternalLoggingEvent(const log4cplus::tstring& logger,
00070                 LogLevel loglevel, const log4cplus::tstring& ndc,
00071                 MappedDiagnosticContextMap const & mdc,
00072                 const log4cplus::tstring& message,
00073                 const log4cplus::tstring& thread,
00074                 log4cplus::helpers::Time time, const log4cplus::tstring& file,
00075                 int line);
00076 
00077             InternalLoggingEvent ();
00078 
00079             InternalLoggingEvent(
00080                 const log4cplus::spi::InternalLoggingEvent& rhs);
00081 
00082             virtual ~InternalLoggingEvent();
00083 
00084             void setLoggingEvent (const log4cplus::tstring & logger,
00085                 LogLevel ll, const log4cplus::tstring & message,
00086                 const char * filename, int line);
00087 
00088             void setFunction (char const * func);
00089             void setFunction (log4cplus::tstring const &);
00090 
00091 
00092           // public virtual methods
00094             virtual const log4cplus::tstring& getMessage() const;
00095 
00100             virtual unsigned int getType() const;
00101 
00105             virtual std::auto_ptr<InternalLoggingEvent> clone() const;
00106 
00107 
00108 
00109           // public methods
00113             const log4cplus::tstring& getLoggerName() const
00114             {
00115                 return loggerName;
00116             }
00117 
00119             LogLevel getLogLevel() const
00120             {
00121                 return ll;
00122             }
00123 
00125             const log4cplus::tstring& getNDC() const
00126             {
00127                 if (!ndcCached)
00128                 {
00129                     ndc = log4cplus::getNDC().get();
00130                     ndcCached = true;
00131                 }
00132                 return ndc;
00133             }
00134 
00135             MappedDiagnosticContextMap const & getMDCCopy () const
00136             {
00137                 if (!mdcCached)
00138                 {
00139                     mdc = log4cplus::getMDC().getContext ();
00140                     mdcCached = true;
00141                 }
00142                 return mdc;
00143             }
00144 
00145             tstring const & getMDC (tstring const & key) const;
00146 
00148             const log4cplus::tstring& getThread() const
00149             {
00150                 if (! threadCached)
00151                 {
00152                     thread = thread::getCurrentThreadName ();
00153                     threadCached = true;
00154                 }
00155                 return thread;
00156             }
00157 
00160             const log4cplus::tstring& getThread2() const
00161             {
00162                 if (! thread2Cached)
00163                 {
00164                     thread2 = thread::getCurrentThreadName2 ();
00165                     thread2Cached = true;
00166                 }
00167                 return thread2;
00168             }
00169 
00170 
00173             const log4cplus::helpers::Time& getTimestamp() const
00174             {
00175                 return timestamp;
00176             }
00177 
00179             const log4cplus::tstring& getFile() const
00180             {
00181                 return file;
00182             }
00183 
00185             int getLine() const { return line; }
00186 
00187             log4cplus::tstring const & getFunction () const
00188             {
00189                 return function;
00190             }
00191 
00192             void gatherThreadSpecificData () const;
00193 
00194             void swap (InternalLoggingEvent &);
00195 
00196           // public operators
00197             log4cplus::spi::InternalLoggingEvent&
00198             operator=(const log4cplus::spi::InternalLoggingEvent& rhs);
00199 
00200           // static methods
00201             static unsigned int getDefaultType();
00202 
00203         protected:
00204           // Data
00205             log4cplus::tstring message;
00206             log4cplus::tstring loggerName;
00207             LogLevel ll;
00208             mutable log4cplus::tstring ndc;
00209             mutable MappedDiagnosticContextMap mdc;
00210             mutable log4cplus::tstring thread;
00211             mutable log4cplus::tstring thread2;
00212             log4cplus::helpers::Time timestamp;
00213             log4cplus::tstring file;
00214             log4cplus::tstring function;
00215             int line;
00217             mutable bool threadCached;
00218             mutable bool thread2Cached;
00220             mutable bool ndcCached;
00222             mutable bool mdcCached;
00223         };
00224 
00225     } // end namespace spi
00226 } // end namespace log4cplus
00227 
00228 #endif // LOG4CPLUS_SPI_INTERNAL_LOGGING_EVENT_HEADER_