00001 // Module: Log4CPLUS 00002 // File: configurator.h 00003 // Created: 3/2003 00004 // Author: Tad E. Smith 00005 // 00006 // 00007 // Copyright 2003-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 _CONFIGURATOR_HEADER_ 00024 #define _CONFIGURATOR_HEADER_ 00025 00026 #include "dcmtk/oflog/config.h" 00027 #include "dcmtk/oflog/appender.h" 00028 #include "dcmtk/oflog/hierarchy.h" 00029 #include "dcmtk/oflog/logger.h" 00030 #include "dcmtk/oflog/helpers/lloguser.h" 00031 #include "dcmtk/oflog/helpers/pointer.h" 00032 #include "dcmtk/oflog/helpers/property.h" 00033 00034 //#include <map> 00035 00036 00037 namespace log4cplus 00038 { 00039 00056 class LOG4CPLUS_EXPORT PropertyConfigurator 00057 : protected log4cplus::helpers::LogLogUser 00058 { 00059 public: 00060 enum PCFlags 00061 { 00062 fRecursiveExpansion = 0x0001, 00063 fShadowEnvironment = 0x0002, 00064 fAllowEmptyVars = 0x0004 00065 }; 00066 00067 // ctor and dtor 00068 PropertyConfigurator(const log4cplus::tstring& propertyFile, 00069 Hierarchy& h = Logger::getDefaultHierarchy(), unsigned flags = 0); 00070 PropertyConfigurator(const log4cplus::helpers::Properties& props, 00071 Hierarchy& h = Logger::getDefaultHierarchy(), unsigned flags = 0); 00072 PropertyConfigurator(log4cplus::tistream& propertyStream, 00073 Hierarchy& h = Logger::getDefaultHierarchy(), unsigned flags = 0); 00074 virtual ~PropertyConfigurator(); 00075 00085 static void doConfigure(const log4cplus::tstring& configFilename, 00086 Hierarchy& h = Logger::getDefaultHierarchy(), unsigned flags = 0); 00087 00234 virtual void configure(); 00235 00242 log4cplus::helpers::Properties const & getProperties () const; 00243 00251 log4cplus::tstring const & getPropertyFilename () const; 00252 00253 protected: 00254 // Methods 00255 void init(); // called by the ctor 00256 void reconfigure(); 00257 void replaceEnvironVariables(); 00258 void configureLoggers(); 00259 void configureLogger(log4cplus::Logger logger, const log4cplus::tstring& config); 00260 void configureAppenders(); 00261 void configureAdditivity(); 00262 00263 virtual Logger getLogger(const log4cplus::tstring& name); 00264 virtual void addAppender(Logger &logger, log4cplus::SharedAppenderPtr& appender); 00265 00266 // Types 00267 typedef OFMap<log4cplus::tstring, log4cplus::SharedAppenderPtr> AppenderMap; 00268 00269 // Data 00270 Hierarchy& h; 00271 log4cplus::tstring propertyFilename; 00272 log4cplus::helpers::Properties properties; 00273 AppenderMap appenders; 00274 unsigned flags; 00275 00276 private: 00277 // Disable copy 00278 PropertyConfigurator(const PropertyConfigurator&); 00279 PropertyConfigurator& operator=(PropertyConfigurator&); 00280 }; 00281 00282 00283 00291 class LOG4CPLUS_EXPORT BasicConfigurator : public PropertyConfigurator { 00292 public: 00293 // ctor and dtor 00294 BasicConfigurator(Hierarchy& h = Logger::getDefaultHierarchy()); 00295 virtual ~BasicConfigurator(); 00296 00306 static void doConfigure(Hierarchy& h = Logger::getDefaultHierarchy()); 00307 00308 private: 00309 // Disable copy 00310 BasicConfigurator(const BasicConfigurator&); 00311 BasicConfigurator& operator=(BasicConfigurator&); 00312 }; 00313 00314 00315 #if !defined(LOG4CPLUS_SINGLE_THREADED) 00316 // Forward Declarations 00317 class ConfigurationWatchDogThread; 00318 00319 00320 class LOG4CPLUS_EXPORT ConfigureAndWatchThread { 00321 public: 00322 // ctor and dtor 00323 ConfigureAndWatchThread(const log4cplus::tstring& propertyFile, 00324 unsigned int millis = 60 * 1000); 00325 virtual ~ConfigureAndWatchThread(); 00326 00327 private: 00328 // Disallow copying of instances of this class 00329 ConfigureAndWatchThread(const ConfigureAndWatchThread&); 00330 ConfigureAndWatchThread& operator=(const ConfigureAndWatchThread&); 00331 00332 // Data 00333 ConfigurationWatchDogThread * watchDogThread; 00334 }; 00335 #endif 00336 00337 } // end namespace log4cplus 00338 00339 #endif // _CONFIGURATOR_HEADER_ 00340