log4cplus  2.0.6
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 
267  virtual void configure();
268 
275  log4cplus::helpers::Properties const & getProperties () const;
276 
284  log4cplus::tstring const & getPropertyFilename () const;
285 
286  protected:
287  // Methods
288  void init(); // called by the ctor
289  void reconfigure();
290  void replaceEnvironVariables();
291  void configureLoggers();
292  void configureLogger(log4cplus::Logger logger, const log4cplus::tstring& config);
293  void configureAppenders();
294  void configureAdditivity();
295 
296  virtual Logger getLogger(const log4cplus::tstring& name);
297  virtual void addAppender(Logger &logger, log4cplus::SharedAppenderPtr& appender);
298 
299  // Types
300  typedef std::map<log4cplus::tstring, log4cplus::SharedAppenderPtr> AppenderMap;
301 
302  // Data
307  unsigned flags;
308 
309  private:
310  // Disable copy
313  };
314 
315 
316 
326  public:
327  // ctor and dtor
329  bool logToStdErr = false);
330  virtual ~BasicConfigurator();
331 
341  static void doConfigure(Hierarchy& h = Logger::getDefaultHierarchy(),
342  bool logToStdErr = false);
343 
346 
347  private:
348  // Disable copy
351  };
352 
353 
354 #if !defined(LOG4CPLUS_SINGLE_THREADED)
355  // Forward Declarations
356  class ConfigurationWatchDogThread;
357 
358 
360  public:
361  // ctor and dtor
362  ConfigureAndWatchThread(const log4cplus::tstring& propertyFile,
363  unsigned int millis = 60 * 1000);
364  virtual ~ConfigureAndWatchThread();
365 
366  private:
367  // Disallow copying of instances of this class
370 
371  // Data
372  ConfigurationWatchDogThread * watchDogThread;
373  };
374 #endif
375 
376 } // end namespace log4cplus
377 
378 #endif // LOG4CPLUS_CONFIGURATOR_HEADER_
log4cplus
Definition: appender.h:46
log4cplus::tstring
std::basic_string< tchar > tstring
Definition: tstring.h:39
log4cplus::helpers::SharedObjectPtr
Definition: pointer.h:100
logger.h
log4cplus::BasicConfigurator::DISABLE_OVERRIDE_KEY
static const log4cplus::tstring DISABLE_OVERRIDE_KEY
Property name for disable override.
Definition: configurator.h:345
log4cplus::PropertyConfigurator::propertyFilename
log4cplus::tstring propertyFilename
Definition: configurator.h:304
property.h
log4cplus::PropertyConfigurator::h
Hierarchy & h
Definition: configurator.h:303
log4cplus::BasicConfigurator
Use this class to quickly configure the package.
Definition: configurator.h:325
log4cplus::PropertyConfigurator::properties
log4cplus::helpers::Properties properties
Definition: configurator.h:305
log4cplus::PropertyConfigurator::AppenderMap
std::map< log4cplus::tstring, log4cplus::SharedAppenderPtr > AppenderMap
Definition: configurator.h:300
config.hxx
log4cplus::helpers::Properties
Definition: property.h:43
pointer.h
log4cplus::Hierarchy
This class is specialized in retrieving loggers by name and also maintaining the logger hierarchy.
Definition: hierarchy.h:63
log4cplus::tistream
std::basic_istream< tchar > tistream
Definition: streams.h:41
log4cplus::PropertyConfigurator::PCFlags
PCFlags
Definition: configurator.h:70
LOG4CPLUS_EXPORT
#define LOG4CPLUS_EXPORT
Definition: win32.h:141
log4cplus::PropertyConfigurator
Provides configuration from an external file.
Definition: configurator.h:67
log4cplus::PropertyConfigurator::appenders
AppenderMap appenders
Definition: configurator.h:306
log4cplus::ConfigureAndWatchThread
Definition: configurator.h:359
log4cplus::Logger::getDefaultHierarchy
static Hierarchy & getDefaultHierarchy()
Return the default Hierarchy instance.
log4cplus::PropertyConfigurator::flags
unsigned flags
Definition: configurator.h:307
appender.h
log4cplus::Logger
This is the central class in the log4cplus package.
Definition: logger.h:69