log4cplus
1.1.0
|
00001 // -*- C++ -*- 00002 // Module: Log4CPLUS 00003 // File: logger.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 00025 #ifndef LOG4CPLUS_LOGGERHEADER_ 00026 #define LOG4CPLUS_LOGGERHEADER_ 00027 00028 #include <log4cplus/config.hxx> 00029 00030 #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE) 00031 #pragma once 00032 #endif 00033 00034 #include <log4cplus/loglevel.h> 00035 #include <log4cplus/tstring.h> 00036 #include <log4cplus/spi/appenderattachable.h> 00037 #include <log4cplus/spi/loggerfactory.h> 00038 00039 #include <vector> 00040 00041 00042 namespace log4cplus 00043 { 00044 // Forward declarations 00045 00046 class Appender; 00047 class Hierarchy; 00048 class HierarchyLocker; 00049 class DefaultLoggerFactory; 00050 00051 namespace spi 00052 { 00053 00054 class LoggerImpl; 00055 00056 } 00057 00058 00061 typedef std::vector<Logger> LoggerList; 00062 00063 00072 class LOG4CPLUS_EXPORT Logger 00073 : public log4cplus::spi::AppenderAttachable 00074 { 00075 public: 00076 // Static Methods 00083 static bool exists(const log4cplus::tstring& name); 00084 00085 /* 00086 * Returns all the currently defined loggers in the default 00087 * hierarchy. 00088 * 00089 * The root logger is <em>not</em> included in the returned 00090 * list. 00091 */ 00092 static LoggerList getCurrentLoggers(); 00093 00097 static Hierarchy& getDefaultHierarchy(); 00098 00110 static Logger getInstance(const log4cplus::tstring& name); 00111 00124 static Logger getInstance(const log4cplus::tstring& name, spi::LoggerFactory& factory); 00125 00136 static Logger getRoot(); 00137 00152 static void shutdown(); 00153 00154 // Non-Static Methods 00163 void assertion(bool assertionVal, const log4cplus::tstring& msg) const; 00164 00169 void closeNestedAppenders() const; 00170 00177 bool isEnabledFor(LogLevel ll) const; 00178 00182 void log(LogLevel ll, const log4cplus::tstring& message, 00183 const char* file=NULL, int line=-1) const; 00184 00185 void log(spi::InternalLoggingEvent const &) const; 00186 00191 void forcedLog(LogLevel ll, const log4cplus::tstring& message, 00192 const char* file=NULL, int line=-1) const; 00193 00194 void forcedLog(spi::InternalLoggingEvent const &) const; 00195 00207 void callAppenders(const spi::InternalLoggingEvent& event) const; 00208 00217 LogLevel getChainedLogLevel() const; 00218 00224 LogLevel getLogLevel() const; 00225 00229 void setLogLevel(LogLevel ll); 00230 00235 Hierarchy& getHierarchy() const; 00236 00240 log4cplus::tstring const & getName() const; 00241 00245 bool getAdditivity() const; 00246 00250 void setAdditivity(bool additive); 00251 00252 // AppenderAttachable Methods 00253 virtual void addAppender(SharedAppenderPtr newAppender); 00254 00255 virtual SharedAppenderPtrList getAllAppenders(); 00256 00257 virtual SharedAppenderPtr getAppender(const log4cplus::tstring& name); 00258 00259 virtual void removeAllAppenders(); 00260 00261 virtual void removeAppender(SharedAppenderPtr appender); 00262 00263 virtual void removeAppender(const log4cplus::tstring& name); 00264 00265 Logger (); 00266 Logger(const Logger& rhs); 00267 Logger& operator=(const Logger& rhs); 00268 #if defined (LOG4CPLUS_HAVE_RVALUE_REFS) 00269 Logger (Logger && rhs); 00270 Logger & operator = (Logger && rhs); 00271 #endif 00272 virtual ~Logger(); 00273 00274 void swap (Logger &); 00275 00280 Logger getParent() const; 00281 00282 protected: 00283 // Data 00285 spi::LoggerImpl * value; 00286 00287 private: 00288 // Ctors 00298 LOG4CPLUS_PRIVATE Logger(spi::LoggerImpl * ptr); 00299 00300 // Friends 00301 friend class log4cplus::spi::LoggerImpl; 00302 friend class log4cplus::Hierarchy; 00303 friend class log4cplus::HierarchyLocker; 00304 friend class log4cplus::DefaultLoggerFactory; 00305 }; 00306 00307 00312 class LOG4CPLUS_EXPORT DefaultLoggerFactory : public spi::LoggerFactory { 00313 public: 00314 Logger makeNewLoggerInstance(const log4cplus::tstring& name, Hierarchy& h); 00315 }; 00316 00317 00318 } // end namespace log4cplus 00319 00320 00321 #endif // LOG4CPLUS_LOGGERHEADER_