log4cplus  2.0.0
configurator.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 // Module: Log4CPLUS
3 // File: configurator.h
4 // Created: 3/2003
5 // Author: Tad E. Smith
6 //
7 //
8 // Copyright 2003-2017 Tad E. Smith
9 //
10 // Licensed under the Apache License, Version 2.0 (the "License");
11 // you may not use this file except in compliance with the License.
12 // You may obtain a copy of the License at
13 //
14 // http://www.apache.org/licenses/LICENSE-2.0
15 //
16 // Unless required by applicable law or agreed to in writing, software
17 // distributed under the License is distributed on an "AS IS" BASIS,
18 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 // See the License for the specific language governing permissions and
20 // limitations under the License.
21 
24 #ifndef LOG4CPLUS_CONFIGURATOR_HEADER_
25 #define LOG4CPLUS_CONFIGURATOR_HEADER_
26 
27 #include <log4cplus/config.hxx>
28 
29 #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE)
30 #pragma once
31 #endif
32 
33 #include <log4cplus/appender.h>
34 #include <log4cplus/logger.h>
37 
38 #include <map>
39 
40 
41 namespace log4cplus
42 {
43  class Hierarchy;
44 
45 
68  {
69  public:
70  enum PCFlags
71  {
72  fRecursiveExpansion = (1 << 0)
73  , fShadowEnvironment = (1 << 1)
74  , fAllowEmptyVars = (1 << 2)
75 
76  // These encoding related options occupy 2 bits of the flags
77  // and are mutually exclusive. These flags are synchronized with
78  // PFlags in Properties.
79 
80  , fEncodingShift = 3
81  , fEncodingMask = 0x3
82  , fUnspecEncoding = (0 << fEncodingShift)
83 #if defined (LOG4CPLUS_HAVE_CODECVT_UTF8_FACET) && defined (UNICODE)
84  , fUTF8 = (1 << fEncodingShift)
85 #endif
86 #if (defined (LOG4CPLUS_HAVE_CODECVT_UTF16_FACET) || defined (_WIN32)) \
87  && defined (UNICODE)
88  , fUTF16 = (2 << fEncodingShift)
89 #endif
90 #if defined (LOG4CPLUS_HAVE_CODECVT_UTF32_FACET) && defined (UNICODE)
91  , fUTF32 = (3 << fEncodingShift)
92 #endif
93  };
94 
95  // ctor and dtor
96  PropertyConfigurator(const log4cplus::tstring& propertyFile,
97  Hierarchy& h = Logger::getDefaultHierarchy(), unsigned flags = 0);
99  Hierarchy& h = Logger::getDefaultHierarchy(), unsigned flags = 0);
101  Hierarchy& h = Logger::getDefaultHierarchy(), unsigned flags = 0);
102  virtual ~PropertyConfigurator();
103 
113  static void doConfigure(const log4cplus::tstring& configFilename,
114  Hierarchy& h = Logger::getDefaultHierarchy(), unsigned flags = 0);
115 
262  virtual void configure();
263 
270  log4cplus::helpers::Properties const & getProperties () const;
271 
279  log4cplus::tstring const & getPropertyFilename () const;
280 
281  protected:
282  // Methods
283  void init(); // called by the ctor
284  void reconfigure();
285  void replaceEnvironVariables();
286  void configureLoggers();
287  void configureLogger(log4cplus::Logger logger, const log4cplus::tstring& config);
288  void configureAppenders();
289  void configureAdditivity();
290 
291  virtual Logger getLogger(const log4cplus::tstring& name);
292  virtual void addAppender(Logger &logger, log4cplus::SharedAppenderPtr& appender);
293 
294  // Types
295  typedef std::map<log4cplus::tstring, log4cplus::SharedAppenderPtr> AppenderMap;
296 
297  // Data
302  unsigned flags;
303 
304  private:
305  // Disable copy
308  };
309 
310 
311 
321  public:
322  // ctor and dtor
324  bool logToStdErr = false);
325  virtual ~BasicConfigurator();
326 
336  static void doConfigure(Hierarchy& h = Logger::getDefaultHierarchy(),
337  bool logToStdErr = false);
338 
341 
342  private:
343  // Disable copy
346  };
347 
348 
349 #if !defined(LOG4CPLUS_SINGLE_THREADED)
350  // Forward Declarations
351  class ConfigurationWatchDogThread;
352 
353 
355  public:
356  // ctor and dtor
357  ConfigureAndWatchThread(const log4cplus::tstring& propertyFile,
358  unsigned int millis = 60 * 1000);
359  virtual ~ConfigureAndWatchThread();
360 
361  private:
362  // Disallow copying of instances of this class
365 
366  // Data
367  ConfigurationWatchDogThread * watchDogThread;
368  };
369 #endif
370 
371 } // end namespace log4cplus
372 
373 #endif // LOG4CPLUS_CONFIGURATOR_HEADER_
static log4cplus::tstring const DISABLE_OVERRIDE_KEY
Property name for disable override.
Definition: configurator.h:340
#define LOG4CPLUS_EXPORT
Definition: win32.h:141
This is the central class in the log4cplus package.
Definition: logger.h:69
log4cplus::helpers::Properties properties
Definition: configurator.h:300
Provides configuration from an external file.
Definition: configurator.h:67
std::map< log4cplus::tstring, log4cplus::SharedAppenderPtr > AppenderMap
Definition: configurator.h:295
std::basic_string< tchar > tstring
Definition: tstring.h:39
std::basic_istream< tchar > tistream
Definition: streams.h:41
This class is specialized in retrieving loggers by name and also maintaining the logger hierarchy.
Definition: hierarchy.h:63
This header defines the Logger class and the logging macros.
Use this class to quickly configure the package.
Definition: configurator.h:320
static Hierarchy & getDefaultHierarchy()
Return the default Hierarchy instance.
log4cplus::tstring propertyFilename
Definition: configurator.h:299