API Documentation
00001 // Module: Log4CPLUS 00002 // File: loggingevent.h 00003 // Created: 6/2001 00004 // Author: Tad E. Smith 00005 // 00006 // 00007 // Copyright (C) Tad E. Smith All rights reserved. 00008 // 00009 // This software is published under the terms of the Apache Software 00010 // License version 1.1, a copy of which has been included with this 00011 // distribution in the LICENSE.APL file. 00012 // 00013 00016 #ifndef _LOG4CPLUS_SPI_INTERNAL_LOGGING_EVENT_HEADER_ 00017 #define _LOG4CPLUS_SPI_INTERNAL_LOGGING_EVENT_HEADER_ 00018 00019 #include <log4cplus/config.h> 00020 #include <log4cplus/loglevel.h> 00021 #include <log4cplus/ndc.h> 00022 #include <log4cplus/tstring.h> 00023 #include <log4cplus/helpers/timehelper.h> 00024 #include <log4cplus/helpers/threads.h> 00025 00026 namespace log4cplus { 00027 namespace spi { 00036 class LOG4CPLUS_EXPORT InternalLoggingEvent { 00037 public: 00038 // Ctors 00046 InternalLoggingEvent(const log4cplus::tstring& logger, 00047 LogLevel ll, 00048 const log4cplus::tstring& message, 00049 const char* filename, 00050 int line) 00051 : message(message), 00052 loggerName(logger), 00053 ll(ll), 00054 ndc(), 00055 thread(), 00056 timestamp(log4cplus::helpers::Time::gettimeofday()), 00057 file( ( filename 00058 ? LOG4CPLUS_C_STR_TO_TSTRING(filename) 00059 : log4cplus::tstring()) ), 00060 line(line), 00061 threadCached(false), 00062 ndcCached(false) 00063 { 00064 } 00065 00066 InternalLoggingEvent(const log4cplus::tstring& logger, 00067 LogLevel ll, 00068 const log4cplus::tstring& ndc, 00069 const log4cplus::tstring& message, 00070 const log4cplus::tstring& thread, 00071 log4cplus::helpers::Time time, 00072 const log4cplus::tstring& file, 00073 int line) 00074 : message(message), 00075 loggerName(logger), 00076 ll(ll), 00077 ndc(ndc), 00078 thread(thread), 00079 timestamp(time), 00080 file(file), 00081 line(line), 00082 threadCached(true), 00083 ndcCached(true) 00084 { 00085 } 00086 00087 InternalLoggingEvent(const log4cplus::spi::InternalLoggingEvent& rhs) 00088 : message(rhs.getMessage()), 00089 loggerName(rhs.getLoggerName()), 00090 ll(rhs.getLogLevel()), 00091 ndc(rhs.getNDC()), 00092 thread(rhs.getThread()), 00093 timestamp(rhs.getTimestamp()), 00094 file(rhs.getFile()), 00095 line(rhs.getLine()), 00096 threadCached(true), 00097 ndcCached(true) 00098 { 00099 } 00100 00101 virtual ~InternalLoggingEvent(); 00102 00103 00104 // public virtual methods 00106 virtual const log4cplus::tstring& getMessage() const; 00107 00112 virtual unsigned int getType() const; 00113 00117 virtual std::auto_ptr<InternalLoggingEvent> clone() const; 00118 00119 00120 00121 // public methods 00125 const log4cplus::tstring& getLoggerName() const { return loggerName; } 00126 00128 LogLevel getLogLevel() const { return ll; } 00129 00131 const log4cplus::tstring& getNDC() const { 00132 if(!ndcCached) { 00133 ndc = log4cplus::getNDC().get(); 00134 ndcCached = true; 00135 } 00136 return ndc; 00137 } 00138 00140 const log4cplus::tstring& getThread() const { 00141 if(!threadCached) { 00142 thread = LOG4CPLUS_GET_CURRENT_THREAD_NAME; 00143 threadCached = true; 00144 } 00145 return thread; 00146 } 00147 00150 const log4cplus::helpers::Time& getTimestamp() const { return timestamp; } 00151 00153 const log4cplus::tstring& getFile() const { return file; } 00154 00156 int getLine() const { return line; } 00157 00158 // public operators 00159 log4cplus::spi::InternalLoggingEvent& 00160 operator=(const log4cplus::spi::InternalLoggingEvent& rhs); 00161 00162 // static methods 00163 static unsigned int getDefaultType(); 00164 00165 protected: 00166 // Data 00167 log4cplus::tstring message; 00168 00169 private: 00170 log4cplus::tstring loggerName; 00171 LogLevel ll; 00172 mutable log4cplus::tstring ndc; 00173 mutable log4cplus::tstring thread; 00174 log4cplus::helpers::Time timestamp; 00175 log4cplus::tstring file; 00176 int line; 00178 mutable bool threadCached; 00180 mutable bool ndcCached; 00181 }; 00182 00183 } // end namespace spi 00184 } // end namespace log4cplus 00185 00186 #endif // _LOG4CPLUS_SPI_INTERNAL_LOGGING_EVENT_HEADER_ 00187