configurator.h
Go to the documentation of this file.
// -*- C++ -*-
// Module: Log4CPLUS
// File: configurator.h
// Created: 3/2003
// Author: Tad E. Smith
//
//
// Copyright 2003-2017 Tad E. Smith
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef LOG4CPLUS_CONFIGURATOR_HEADER_
#define LOG4CPLUS_CONFIGURATOR_HEADER_
#include <log4cplus/config.hxx>
#if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE)
#pragma once
#endif
#include <log4cplus/appender.h>
#include <log4cplus/logger.h>
#include <log4cplus/helpers/pointer.h>
#include <log4cplus/helpers/property.h>
#include <map>
namespace log4cplus
{
class Hierarchy;
class LOG4CPLUS_EXPORT PropertyConfigurator
{
public:
enum PCFlags
{
fRecursiveExpansion = (1 << 0)
, fShadowEnvironment = (1 << 1)
, fAllowEmptyVars = (1 << 2)
// These encoding related options occupy 2 bits of the flags
// and are mutually exclusive. These flags are synchronized with
// PFlags in Properties.
, fEncodingShift = 3
, fEncodingMask = 0x3
, fUnspecEncoding = (0 << fEncodingShift)
#if defined (LOG4CPLUS_HAVE_CODECVT_UTF8_FACET) && defined (UNICODE)
, fUTF8 = (1 << fEncodingShift)
#endif
#if (defined (LOG4CPLUS_HAVE_CODECVT_UTF16_FACET) || defined (_WIN32)) \
&& defined (UNICODE)
, fUTF16 = (2 << fEncodingShift)
#endif
#if defined (LOG4CPLUS_HAVE_CODECVT_UTF32_FACET) && defined (UNICODE)
, fUTF32 = (3 << fEncodingShift)
#endif
, fThrow = (1 << 5)
};
// ctor and dtor
PropertyConfigurator(const log4cplus::tstring& propertyFile,
Hierarchy& h = Logger::getDefaultHierarchy(), unsigned flags = 0);
PropertyConfigurator(const log4cplus::helpers::Properties& props,
Hierarchy& h = Logger::getDefaultHierarchy(), unsigned flags = 0);
PropertyConfigurator(log4cplus::tistream& propertyStream,
Hierarchy& h = Logger::getDefaultHierarchy(), unsigned flags = 0);
virtual ~PropertyConfigurator();
static void doConfigure(const log4cplus::tstring& configFilename,
Hierarchy& h = Logger::getDefaultHierarchy(), unsigned flags = 0);
virtual void configure();
log4cplus::helpers::Properties const & getProperties () const;
log4cplus::tstring const & getPropertyFilename () const;
protected:
// Methods
void init(); // called by the ctor
void reconfigure();
void replaceEnvironVariables();
void configureLoggers();
void configureLogger(log4cplus::Logger logger, const log4cplus::tstring& config);
void configureAppenders();
void configureAdditivity();
virtual Logger getLogger(const log4cplus::tstring& name);
virtual void addAppender(Logger &logger, log4cplus::SharedAppenderPtr& appender);
// Types
typedef std::map<log4cplus::tstring, log4cplus::SharedAppenderPtr> AppenderMap;
// Data
Hierarchy& h;
log4cplus::tstring propertyFilename;
log4cplus::helpers::Properties properties;
AppenderMap appenders;
unsigned flags;
private:
// Disable copy
PropertyConfigurator(const PropertyConfigurator&);
PropertyConfigurator& operator=(PropertyConfigurator&);
};
class LOG4CPLUS_EXPORT BasicConfigurator : public PropertyConfigurator {
public:
// ctor and dtor
BasicConfigurator(Hierarchy& h = Logger::getDefaultHierarchy(),
bool logToStdErr = false);
virtual ~BasicConfigurator();
static void doConfigure(Hierarchy& h = Logger::getDefaultHierarchy(),
bool logToStdErr = false);
static log4cplus::tstring const DISABLE_OVERRIDE_KEY;
private:
// Disable copy
BasicConfigurator(const BasicConfigurator&);
BasicConfigurator& operator=(BasicConfigurator&);
};
#if !defined(LOG4CPLUS_SINGLE_THREADED)
// Forward Declarations
class ConfigurationWatchDogThread;
class LOG4CPLUS_EXPORT ConfigureAndWatchThread {
public:
// ctor and dtor
ConfigureAndWatchThread(const log4cplus::tstring& propertyFile,
unsigned int millis = 60 * 1000);
virtual ~ConfigureAndWatchThread();
private:
// Disallow copying of instances of this class
ConfigureAndWatchThread(const ConfigureAndWatchThread&);
ConfigureAndWatchThread& operator=(const ConfigureAndWatchThread&);
// Data
ConfigurationWatchDogThread * watchDogThread;
};
#endif
} // end namespace log4cplus
#endif // LOG4CPLUS_CONFIGURATOR_HEADER_
appender.h
log4cplus::BasicConfigurator::~BasicConfigurator
virtual ~BasicConfigurator()
log4cplus::BasicConfigurator::BasicConfigurator
BasicConfigurator(Hierarchy &h=Logger::getDefaultHierarchy(), bool logToStdErr=false)
log4cplus::BasicConfigurator::doConfigure
static void doConfigure(Hierarchy &h=Logger::getDefaultHierarchy(), bool logToStdErr=false)
This method eliminates the need to create a temporary BasicConfigurator object to configure log4cplus...
log4cplus::BasicConfigurator::DISABLE_OVERRIDE_KEY
static log4cplus::tstring const DISABLE_OVERRIDE_KEY
Property name for disable override.
Definition configurator.h:356
log4cplus::ConfigureAndWatchThread::ConfigureAndWatchThread
ConfigureAndWatchThread(const log4cplus::tstring &propertyFile, unsigned int millis=60 *1000)
log4cplus::ConfigureAndWatchThread::~ConfigureAndWatchThread
virtual ~ConfigureAndWatchThread()
log4cplus::Hierarchy
This class is specialized in retrieving loggers by name and also maintaining the logger hierarchy.
Definition hierarchy.h:64
log4cplus::Logger
This is the central class in the log4cplus package.
Definition logger.h:71
log4cplus::Logger::getDefaultHierarchy
static Hierarchy & getDefaultHierarchy()
Return the default Hierarchy instance.
log4cplus::PropertyConfigurator::configureAdditivity
void configureAdditivity()
log4cplus::PropertyConfigurator::propertyFilename
log4cplus::tstring propertyFilename
Definition configurator.h:315
log4cplus::PropertyConfigurator::getPropertyFilename
log4cplus::tstring const & getPropertyFilename() const
log4cplus::PropertyConfigurator::PropertyConfigurator
PropertyConfigurator(const log4cplus::helpers::Properties &props, Hierarchy &h=Logger::getDefaultHierarchy(), unsigned flags=0)
log4cplus::PropertyConfigurator::configure
virtual void configure()
Read configuration from a file.
log4cplus::PropertyConfigurator::properties
log4cplus::helpers::Properties properties
Definition configurator.h:316
log4cplus::PropertyConfigurator::replaceEnvironVariables
void replaceEnvironVariables()
log4cplus::PropertyConfigurator::configureLoggers
void configureLoggers()
log4cplus::PropertyConfigurator::PropertyConfigurator
PropertyConfigurator(log4cplus::tistream &propertyStream, Hierarchy &h=Logger::getDefaultHierarchy(), unsigned flags=0)
log4cplus::PropertyConfigurator::getProperties
log4cplus::helpers::Properties const & getProperties() const
log4cplus::PropertyConfigurator::reconfigure
void reconfigure()
log4cplus::PropertyConfigurator::getLogger
virtual Logger getLogger(const log4cplus::tstring &name)
log4cplus::PropertyConfigurator::AppenderMap
std::map< log4cplus::tstring, log4cplus::SharedAppenderPtr > AppenderMap
Definition configurator.h:311
log4cplus::PropertyConfigurator::~PropertyConfigurator
virtual ~PropertyConfigurator()
log4cplus::PropertyConfigurator::configureAppenders
void configureAppenders()
log4cplus::PropertyConfigurator::doConfigure
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.
log4cplus::PropertyConfigurator::configureLogger
void configureLogger(log4cplus::Logger logger, const log4cplus::tstring &config)
log4cplus::PropertyConfigurator::init
void init()
log4cplus::PropertyConfigurator::appenders
AppenderMap appenders
Definition configurator.h:317
log4cplus::PropertyConfigurator::h
Hierarchy & h
Definition configurator.h:314
log4cplus::PropertyConfigurator::PCFlags
PCFlags
Definition configurator.h:71
log4cplus::PropertyConfigurator::fShadowEnvironment
@ fShadowEnvironment
Definition configurator.h:73
log4cplus::PropertyConfigurator::fRecursiveExpansion
@ fRecursiveExpansion
Definition configurator.h:72
log4cplus::PropertyConfigurator::fEncodingMask
@ fEncodingMask
Definition configurator.h:81
log4cplus::PropertyConfigurator::fUnspecEncoding
@ fUnspecEncoding
Definition configurator.h:82
log4cplus::PropertyConfigurator::fAllowEmptyVars
@ fAllowEmptyVars
Definition configurator.h:74
log4cplus::PropertyConfigurator::fEncodingShift
@ fEncodingShift
Definition configurator.h:80
log4cplus::PropertyConfigurator::fThrow
@ fThrow
Definition configurator.h:93
log4cplus::PropertyConfigurator::PropertyConfigurator
PropertyConfigurator(const log4cplus::tstring &propertyFile, Hierarchy &h=Logger::getDefaultHierarchy(), unsigned flags=0)
log4cplus::PropertyConfigurator::flags
unsigned flags
Definition configurator.h:318
log4cplus::PropertyConfigurator::addAppender
virtual void addAppender(Logger &logger, log4cplus::SharedAppenderPtr &appender)
log4cplus::helpers::Properties
Definition property.h:43
config.hxx
logger.h
This header defines the Logger class and the logging macros.
log4cplus
Definition appender.h:46
log4cplus::SharedAppenderPtr
helpers::SharedObjectPtr< Appender > SharedAppenderPtr
This is a pointer to an Appender.
Definition appender.h:336
log4cplus::tstring
std::basic_string< tchar > tstring
Definition tstring.h:39
log4cplus::tistream
std::basic_istream< tchar > tistream
Definition streams.h:41
pointer.h
property.h
LOG4CPLUS_EXPORT
#define LOG4CPLUS_EXPORT
Definition win32.h:141