Apache log4cxx  Version 0.11.0
propertyconfigurator.h
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #ifndef _LOG4CXX_PROPERTY_CONFIGURATOR_H
19 #define _LOG4CXX_PROPERTY_CONFIGURATOR_H
20 
21 #if defined(_MSC_VER)
22  #pragma warning (push)
23  #pragma warning ( disable: 4231 4251 4275 4786 )
24 #endif
25 
26 
27 #include <log4cxx/helpers/objectptr.h>
28 #include <log4cxx/helpers/objectimpl.h>
29 #include <log4cxx/logstring.h>
30 #include <log4cxx/spi/configurator.h>
31 #include <map>
32 
33 #include <log4cxx/file.h>
34 
35 namespace log4cxx
36 {
37 class Logger;
38 typedef helpers::ObjectPtrT<Logger> LoggerPtr;
39 
40 class Appender;
41 typedef helpers::ObjectPtrT<Appender> AppenderPtr;
42 
43 namespace helpers
44 {
45 class Properties;
46 }
47 
48 
49 namespace spi
50 {
51 class LoggerFactory;
52 }
53 
54 class PropertyWatchdog;
93 class LOG4CXX_EXPORT PropertyConfigurator :
94  virtual public spi::Configurator,
95  virtual public helpers::ObjectImpl
96 {
97  protected:
98 
102  std::map<LogString, AppenderPtr>* registry;
103 
108 
109  public:
110  DECLARE_LOG4CXX_OBJECT(PropertyConfigurator)
111  BEGIN_LOG4CXX_CAST_MAP()
112  LOG4CXX_CAST_ENTRY(spi::Configurator)
113  END_LOG4CXX_CAST_MAP()
114 
116  virtual ~PropertyConfigurator();
117  void addRef() const;
118  void releaseRef() const;
119 
296  void doConfigure(const File& configFileName,
297  spi::LoggerRepositoryPtr& hierarchy);
298 
302  static void configure(const File& configFilename);
303 
311  static void configureAndWatch(const File& configFilename);
312 
324  static void configureAndWatch(const File& configFilename,
325  long delay);
326 
332  static void configure(helpers::Properties& properties);
333 
339  void doConfigure(helpers::Properties& properties,
340  spi::LoggerRepositoryPtr& hierarchy);
341 
342  // --------------------------------------------------------------------------
343  // Internal stuff
344  // --------------------------------------------------------------------------
345  protected:
355  void configureLoggerFactory(helpers::Properties& props);
356 
357  void configureRootLogger(helpers::Properties& props,
358  spi::LoggerRepositoryPtr& hierarchy);
359 
363  void parseCatsAndRenderers(helpers::Properties& props,
364  spi::LoggerRepositoryPtr& hierarchy);
365 
369  void parseAdditivityForLogger(helpers::Properties& props,
370  LoggerPtr& cat, const LogString& loggerName);
371 
375  void parseLogger(
376  helpers::Properties& props, LoggerPtr& logger,
377  const LogString& optionKey, const LogString& loggerName,
378  const LogString& value);
379 
380  AppenderPtr parseAppender(
381  helpers::Properties& props, const LogString& appenderName);
382 
383  void registryPut(const AppenderPtr& appender);
384  AppenderPtr registryGet(const LogString& name);
385 
386  private:
387  PropertyConfigurator(const PropertyConfigurator&);
388  PropertyConfigurator& operator=(const PropertyConfigurator&);
389  static PropertyWatchdog* pdog;
390 }; // class PropertyConfigurator
391 } // namespace log4cxx
392 
393 #if defined(_MSC_VER)
394  #pragma warning (pop)
395 #endif
396 
397 
398 #endif //_LOG4CXX_PROPERTY_CONFIGURATOR_H
Allows the configuration of log4cxx from an external file.
Definition: propertyconfigurator.h:93
Implementation class for Object.
Definition: objectimpl.h:28
std::map< LogString, AppenderPtr > * registry
Used internally to keep track of configured appenders.
Definition: propertyconfigurator.h:102
helpers::ObjectPtrT< spi::LoggerFactory > loggerFactory
Used to create new instances of logger.
Definition: propertyconfigurator.h:107
Implemented by classes capable of configuring log4j using a URL.
Definition: configurator.h:32
An abstract representation of file and directory path names.
Definition: file.h:45
Definition: appender.h:33
smart pointer to a Object descendant
Definition: objectptr.h:54