log4cplus  2.1.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  , fThrow = (1 << 5)
94  };
95 
96  // ctor and dtor
98  Hierarchy& h = Logger::getDefaultHierarchy(), unsigned flags = 0);
100  Hierarchy& h = Logger::getDefaultHierarchy(), unsigned flags = 0);
102  Hierarchy& h = Logger::getDefaultHierarchy(), unsigned flags = 0);
104 
114  static void doConfigure(const log4cplus::tstring& configFilename,
115  Hierarchy& h = Logger::getDefaultHierarchy(), unsigned flags = 0);
116 
268  virtual void configure();
269 
277 
286 
287  protected:
288  // Methods
289  void init(); // called by the ctor
290  void reconfigure();
296 
297  virtual Logger getLogger(const log4cplus::tstring& name);
298  virtual void addAppender(Logger &logger, log4cplus::SharedAppenderPtr& appender);
299 
300  // Types
301  typedef std::map<log4cplus::tstring, log4cplus::SharedAppenderPtr> AppenderMap;
302 
303  // Data
308  unsigned flags;
309 
310  private:
311  // Disable copy
314  };
315 
316 
317 
327  public:
328  // ctor and dtor
330  bool logToStdErr = false);
332 
343  bool logToStdErr = false);
344 
347 
348  private:
349  // Disable copy
352  };
353 
354 
355 #if !defined(LOG4CPLUS_SINGLE_THREADED)
356  // Forward Declarations
357  class ConfigurationWatchDogThread;
358 
359 
361  public:
362  // ctor and dtor
364  unsigned int millis = 60 * 1000);
366 
367  private:
368  // Disallow copying of instances of this class
371 
372  // Data
373  ConfigurationWatchDogThread * watchDogThread;
374  };
375 #endif
376 
377 } // end namespace log4cplus
378 
379 #endif // LOG4CPLUS_CONFIGURATOR_HEADER_
Use this class to quickly configure the package.
Definition: configurator.h:326
BasicConfigurator(Hierarchy &h=Logger::getDefaultHierarchy(), bool logToStdErr=false)
static void doConfigure(Hierarchy &h=Logger::getDefaultHierarchy(), bool logToStdErr=false)
This method eliminates the need to create a temporary BasicConfigurator object to configure log4cplus...
static log4cplus::tstring const DISABLE_OVERRIDE_KEY
Property name for disable override.
Definition: configurator.h:346
ConfigureAndWatchThread(const log4cplus::tstring &propertyFile, unsigned int millis=60 *1000)
This class is specialized in retrieving loggers by name and also maintaining the logger hierarchy.
Definition: hierarchy.h:64
This is the central class in the log4cplus package.
Definition: logger.h:71
static Hierarchy & getDefaultHierarchy()
Return the default Hierarchy instance.
Provides configuration from an external file.
Definition: configurator.h:68
log4cplus::tstring propertyFilename
Definition: configurator.h:305
PropertyConfigurator(const log4cplus::helpers::Properties &props, Hierarchy &h=Logger::getDefaultHierarchy(), unsigned flags=0)
virtual void configure()
Read configuration from a file.
log4cplus::helpers::Properties properties
Definition: configurator.h:306
log4cplus::tstring const & getPropertyFilename() const
PropertyConfigurator(log4cplus::tistream &propertyStream, Hierarchy &h=Logger::getDefaultHierarchy(), unsigned flags=0)
virtual Logger getLogger(const log4cplus::tstring &name)
std::map< log4cplus::tstring, log4cplus::SharedAppenderPtr > AppenderMap
Definition: configurator.h:301
log4cplus::helpers::Properties const & getProperties() const
static void doConfigure(const log4cplus::tstring &configFilename, Hierarchy &h=Logger::getDefaultHierarchy(), unsigned flags=0)
This method eliminates the need to create a temporary PropertyConfigurator to configure log4cplus.
void configureLogger(log4cplus::Logger logger, const log4cplus::tstring &config)
PropertyConfigurator(const log4cplus::tstring &propertyFile, Hierarchy &h=Logger::getDefaultHierarchy(), unsigned flags=0)
virtual void addAppender(Logger &logger, log4cplus::SharedAppenderPtr &appender)
This header defines the Logger class and the logging macros.
std::basic_string< tchar > tstring
Definition: tstring.h:39
std::basic_istream< tchar > tistream
Definition: streams.h:41
#define LOG4CPLUS_EXPORT
Definition: win32.h:141