log4cplus  2.0.8
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
97  Hierarchy& h = Logger::getDefaultHierarchy(), unsigned flags = 0);
99  Hierarchy& h = Logger::getDefaultHierarchy(), unsigned flags = 0);
101  Hierarchy& h = Logger::getDefaultHierarchy(), unsigned flags = 0);
103 
113  static void doConfigure(const log4cplus::tstring& configFilename,
114  Hierarchy& h = Logger::getDefaultHierarchy(), unsigned flags = 0);
115 
267  virtual void configure();
268 
276 
285 
286  protected:
287  // Methods
288  void init(); // called by the ctor
289  void reconfigure();
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);
331 
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
363  unsigned int millis = 60 * 1000);
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_
Use this class to quickly configure the package.
Definition: configurator.h:325
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:345
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:304
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:305
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:300
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