log4cplus
2.0.0
|
00001 // -*- C++ -*- 00002 // Module: Log4CPLUS 00003 // File: logger.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 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 00069 class LOG4CPLUS_EXPORT Logger 00070 : public log4cplus::spi::AppenderAttachable 00071 { 00072 public: 00073 // Static Methods 00080 static bool exists(const log4cplus::tstring& name); 00081 00082 /* 00083 * Returns all the currently defined loggers in the default 00084 * hierarchy. 00085 * 00086 * The root logger is <em>not</em> included in the returned 00087 * list. 00088 */ 00089 static LoggerList getCurrentLoggers(); 00090 00094 static Hierarchy& getDefaultHierarchy(); 00095 00107 static Logger getInstance(const log4cplus::tstring& name); 00108 00121 static Logger getInstance(const log4cplus::tstring& name, 00122 spi::LoggerFactory& factory); 00123 00134 static Logger getRoot(); 00135 00150 static void shutdown(); 00151 00152 // Non-Static Methods 00161 void assertion(bool assertionVal, const log4cplus::tstring& msg) const; 00162 00167 void closeNestedAppenders() const; 00168 00175 bool isEnabledFor(LogLevel ll) const; 00176 00180 void log(LogLevel ll, const log4cplus::tstring& message, 00181 const char* file = LOG4CPLUS_CALLER_FILE (), 00182 int line = LOG4CPLUS_CALLER_LINE (), 00183 const char* function = LOG4CPLUS_CALLER_FUNCTION ()) const; 00184 00185 void log(spi::InternalLoggingEvent const &) const; 00186 00191 void forcedLog(LogLevel ll, const log4cplus::tstring& message, 00192 const char* file = LOG4CPLUS_CALLER_FILE (), 00193 int line = LOG4CPLUS_CALLER_LINE (), 00194 const char* function = LOG4CPLUS_CALLER_FUNCTION ()) const; 00195 00196 void forcedLog(spi::InternalLoggingEvent const &) const; 00197 00209 void callAppenders(const spi::InternalLoggingEvent& event) const; 00210 00219 LogLevel getChainedLogLevel() const; 00220 00226 LogLevel getLogLevel() const; 00227 00231 void setLogLevel(LogLevel ll); 00232 00237 Hierarchy& getHierarchy() const; 00238 00242 log4cplus::tstring const & getName() const; 00243 00247 bool getAdditivity() const; 00248 00252 void setAdditivity(bool additive); 00253 00254 // AppenderAttachable Methods 00255 virtual void addAppender(SharedAppenderPtr newAppender); 00256 00257 virtual SharedAppenderPtrList getAllAppenders(); 00258 00259 virtual SharedAppenderPtr getAppender(const log4cplus::tstring& name); 00260 00261 virtual void removeAllAppenders(); 00262 00263 virtual void removeAppender(SharedAppenderPtr appender); 00264 00265 virtual void removeAppender(const log4cplus::tstring& name); 00266 00267 Logger () LOG4CPLUS_NOEXCEPT; 00268 Logger(const Logger& rhs) LOG4CPLUS_NOEXCEPT; 00269 Logger& operator=(const Logger& rhs) LOG4CPLUS_NOEXCEPT; 00270 Logger (Logger && rhs) LOG4CPLUS_NOEXCEPT; 00271 Logger & operator = (Logger && rhs) LOG4CPLUS_NOEXCEPT; 00272 virtual ~Logger(); 00273 00274 void swap (Logger &) LOG4CPLUS_NOEXCEPT; 00275 00280 Logger getParent() const; 00281 00282 protected: 00283 // Data 00285 spi::LoggerImpl * value = nullptr; 00286 00287 private: 00288 // Ctors 00298 LOG4CPLUS_PRIVATE Logger(spi::LoggerImpl * ptr) LOG4CPLUS_NOEXCEPT; 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_