log4cplus
1.1.0
|
00001 // -*- C++ -*- 00002 // Module: Log4CPLUS 00003 // File: hierarchy.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_HIERARCHY_HEADER_ 00025 #define LOG4CPLUS_HIERARCHY_HEADER_ 00026 00027 #include <log4cplus/config.hxx> 00028 00029 #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE) 00030 #pragma once 00031 #endif 00032 00033 #include <log4cplus/logger.h> 00034 #include <log4cplus/thread/syncprims.h> 00035 #include <map> 00036 #include <memory> 00037 #include <vector> 00038 00039 00040 namespace log4cplus { 00041 // Forward Declarations 00042 class HierarchyLocker; 00043 00063 class LOG4CPLUS_EXPORT Hierarchy 00064 { 00065 public: 00066 // DISABLE_OFF should be set to a value lower than all possible 00067 // priorities. 00068 static const LogLevel DISABLE_OFF; 00069 static const LogLevel DISABLE_OVERRIDE; 00070 00071 // Ctors 00075 Hierarchy(); 00076 00077 // Dtor 00078 virtual ~Hierarchy(); 00079 00080 // Methods 00089 virtual void clear(); 00090 00097 virtual bool exists(const log4cplus::tstring& name); 00098 00103 virtual void disable(const log4cplus::tstring& loglevelStr); 00104 00122 virtual void disable(LogLevel ll); 00123 00129 virtual void disableAll(); 00130 00136 virtual void disableDebug(); 00137 00143 virtual void disableInfo(); 00144 00152 virtual void enableAll(); 00153 00164 virtual Logger getInstance(const log4cplus::tstring& name); 00165 00178 virtual Logger getInstance(const log4cplus::tstring& name, spi::LoggerFactory& factory); 00179 00185 virtual LoggerList getCurrentLoggers(); 00186 00190 virtual bool isDisabled(LogLevel level); 00191 00195 virtual Logger getRoot() const; 00196 00210 virtual void resetConfiguration(); 00211 00215 virtual void setLoggerFactory(std::auto_ptr<spi::LoggerFactory> factory); 00216 00220 virtual spi::LoggerFactory* getLoggerFactory(); 00221 00235 virtual void shutdown(); 00236 00237 private: 00238 // Types 00239 typedef std::vector<Logger> ProvisionNode; 00240 typedef std::map<log4cplus::tstring, ProvisionNode> ProvisionNodeMap; 00241 typedef std::map<log4cplus::tstring, Logger> LoggerMap; 00242 00243 // Methods 00248 LOG4CPLUS_PRIVATE 00249 virtual Logger getInstanceImpl(const log4cplus::tstring& name, 00250 spi::LoggerFactory& factory); 00251 00256 LOG4CPLUS_PRIVATE 00257 virtual void initializeLoggerList(LoggerList& list) const; 00258 00279 LOG4CPLUS_PRIVATE void updateParents(Logger const & logger); 00280 00295 LOG4CPLUS_PRIVATE void updateChildren(ProvisionNode& pn, 00296 Logger const & logger); 00297 00298 // Data 00299 thread::Mutex hashtable_mutex; 00300 std::auto_ptr<spi::LoggerFactory> defaultFactory; 00301 ProvisionNodeMap provisionNodes; 00302 LoggerMap loggerPtrs; 00303 Logger root; 00304 00305 int disableValue; 00306 00307 bool emittedNoAppenderWarning; 00308 00309 // Disallow copying of instances of this class 00310 Hierarchy(const Hierarchy&); 00311 Hierarchy& operator=(const Hierarchy&); 00312 00313 // Friends 00314 friend class log4cplus::spi::LoggerImpl; 00315 friend class log4cplus::HierarchyLocker; 00316 }; 00317 00318 00319 LOG4CPLUS_EXPORT Hierarchy & getDefaultHierarchy (); 00320 00321 00322 } // end namespace log4cplus 00323 00324 #endif // LOG4CPLUS_HIERARCHY_HEADER_ 00325