00001 // Module: Log4CPLUS 00002 // File: loggingevent.h 00003 // Created: 6/2001 00004 // Author: Tad E. Smith 00005 // 00006 // 00007 // Copyright 2001-2009 Tad E. Smith 00008 // 00009 // Licensed under the Apache License, Version 2.0 (the "License"); 00010 // you may not use this file except in compliance with the License. 00011 // You may obtain a copy of the License at 00012 // 00013 // http://www.apache.org/licenses/LICENSE-2.0 00014 // 00015 // Unless required by applicable law or agreed to in writing, software 00016 // distributed under the License is distributed on an "AS IS" BASIS, 00017 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00018 // See the License for the specific language governing permissions and 00019 // limitations under the License. 00020 00023 #ifndef _LOG4CPLUS_SPI_INTERNAL_LOGGING_EVENT_HEADER_ 00024 #define _LOG4CPLUS_SPI_INTERNAL_LOGGING_EVENT_HEADER_ 00025 00026 #include "dcmtk/oflog/config.h" 00027 #include "dcmtk/oflog/loglevel.h" 00028 #include "dcmtk/oflog/ndc.h" 00029 #include "dcmtk/oflog/tstring.h" 00030 #include "dcmtk/oflog/helpers/timehelp.h" 00031 #include "dcmtk/oflog/helpers/threads.h" 00032 00033 #include "dcmtk/ofstd/ofaptr.h" 00034 00035 namespace log4cplus { 00036 namespace spi { 00045 class LOG4CPLUS_EXPORT InternalLoggingEvent { 00046 public: 00047 // Ctors 00060 InternalLoggingEvent(const log4cplus::tstring& logger, 00061 LogLevel ll_, 00062 const log4cplus::tstring& message_, 00063 const char* filename, 00064 int line_, 00065 const char* function_) 00066 : message(message_), 00067 loggerName(logger), 00068 ll(ll_), 00069 ndc(), 00070 thread(), 00071 timestamp(log4cplus::helpers::Time::gettimeofday()), 00072 file( ( filename 00073 ? LOG4CPLUS_C_STR_TO_TSTRING(filename) 00074 : log4cplus::tstring()) ), 00075 line(line_), 00076 function( ( function_ 00077 ? LOG4CPLUS_C_STR_TO_TSTRING(function_) 00078 : log4cplus::tstring()) ), 00079 threadCached(false), 00080 ndcCached(false) 00081 { 00082 } 00083 00084 InternalLoggingEvent(const log4cplus::tstring& logger, 00085 LogLevel ll_, 00086 const log4cplus::tstring& ndc_, 00087 const log4cplus::tstring& message_, 00088 const log4cplus::tstring& thread_, 00089 log4cplus::helpers::Time time, 00090 const log4cplus::tstring& file_, 00091 int line_, 00092 const log4cplus::tstring& function_) 00093 : message(message_), 00094 loggerName(logger), 00095 ll(ll_), 00096 ndc(ndc_), 00097 thread(thread_), 00098 timestamp(time), 00099 file(file_), 00100 line(line_), 00101 function(function_), 00102 threadCached(true), 00103 ndcCached(true) 00104 { 00105 } 00106 00107 InternalLoggingEvent(const log4cplus::spi::InternalLoggingEvent& rhs) 00108 : message(rhs.getMessage()), 00109 loggerName(rhs.getLoggerName()), 00110 ll(rhs.getLogLevel()), 00111 ndc(rhs.getNDC()), 00112 thread(rhs.getThread()), 00113 timestamp(rhs.getTimestamp()), 00114 file(rhs.getFile()), 00115 line(rhs.getLine()), 00116 function(rhs.getFunction()), 00117 threadCached(true), 00118 ndcCached(true) 00119 { 00120 } 00121 00122 virtual ~InternalLoggingEvent(); 00123 00124 00125 // public virtual methods 00127 virtual const log4cplus::tstring& getMessage() const; 00128 00133 virtual unsigned int getType() const; 00134 00138 virtual OFauto_ptr<InternalLoggingEvent> clone() const; 00139 00140 00141 00142 // public methods 00146 const log4cplus::tstring& getLoggerName() const { return loggerName; } 00147 00149 LogLevel getLogLevel() const { return ll; } 00150 00152 const log4cplus::tstring& getNDC() const { 00153 if(!ndcCached) { 00154 ndc = log4cplus::getNDC().get(); 00155 ndcCached = true; 00156 } 00157 return ndc; 00158 } 00159 00161 const log4cplus::tstring& getThread() const { 00162 if(!threadCached) { 00163 thread = LOG4CPLUS_GET_CURRENT_THREAD_NAME; 00164 threadCached = true; 00165 } 00166 return thread; 00167 } 00168 00171 const log4cplus::helpers::Time& getTimestamp() const { return timestamp; } 00172 00174 const log4cplus::tstring& getFile() const { return file; } 00175 00177 int getLine() const { return line; } 00178 00180 const log4cplus::tstring& getFunction() const { return function; } 00181 00182 // public operators 00183 log4cplus::spi::InternalLoggingEvent& 00184 operator=(const log4cplus::spi::InternalLoggingEvent& rhs); 00185 00186 // static methods 00187 static unsigned int getDefaultType(); 00188 00189 protected: 00190 // Data 00191 log4cplus::tstring message; 00192 00193 private: 00194 log4cplus::tstring loggerName; 00195 LogLevel ll; 00196 mutable log4cplus::tstring ndc; 00197 mutable log4cplus::tstring thread; 00198 log4cplus::helpers::Time timestamp; 00199 log4cplus::tstring file; 00200 int line; 00201 log4cplus::tstring function; 00203 mutable bool threadCached; 00205 mutable bool ndcCached; 00206 }; 00207 00208 } // end namespace spi 00209 } // end namespace log4cplus 00210 00211 #endif // _LOG4CPLUS_SPI_INTERNAL_LOGGING_EVENT_HEADER_