Apache Log4cxx  Version 2.0.0
Loading...
Searching...
No Matches
log4cxx::DefaultConfigurator Class Reference

Configures the repository from environmental settings and files. More...

#include <defaultconfigurator.h>

Static Public Member Functions

static spi::ConfigurationStatus configure (const spi::LoggerRepositoryPtr &repository={})
 Configure repository.
static LogString setConfiguratorClass (const LogString &className)
 Instantiate an instance of className to process the configuration file used by configure().
static LogString setConfigurationFileName (const LogString &path)
 Make path the configuration file used by configure().
static int setConfigurationWatchSeconds (int seconds)
 Make seconds the time a background task will delay before checking for a change to the configuration file used by configure().
static std::tuple< spi::ConfigurationStatus, LogString > configureFromFile (const std::vector< LogString > &directories, const std::vector< LogString > &filenames)
 Call configure() passing the default repository after calling setConfigurationFileName() with a path composed of an entry in directories and an entry in filenames when the combination identifies an existing file.

Detailed Description

Configures the repository from environmental settings and files.

Member Function Documentation

◆ configure()

spi::ConfigurationStatus log4cxx::DefaultConfigurator::configure ( const spi::LoggerRepositoryPtr & repository = {})
static

Configure repository.

If the configuration file name has not been provided by a call to setConfigurationFileName(), the environment variable "LOG4CXX_CONFIGURATION" value is used, with ${varname} instances using either a system environment variable value (if found) otherwise using the helpers::Properties object provided by spi::Configurator::properties.

Example usage:
setenv LOG4CXX_CONFIGURATION="${PROGRAM_FILE_PATH.PARENT_PATH}/${PROGRAM_FILE_PATH.STEM}.xml"

If the configuration file name is not specified, the current directory is examined for a file with extension ".xml" or ".properties" with a base name "log4cxx" or "log4j".

Unless a configurator is specified using the "LOG4CXX_CONFIGURATOR_CLASS" environment variable, or by a call to setConfiguratorClass(), Log4cxx will call the spi::Configurator::isValid method on an instance of each class registered with Log4cxx whose name ends with "Configurator". The first configurator instance whose spi::Configurator::isValid method returns true is used to process the configuration file.

If a positive number has been provided by a call to setConfigurationWatchSeconds() or the environment variables "LOG4CXX_CONFIGURATION_WATCH_SECONDS" contains a positive number a background task is started that will periodically check for a change to the configuration file and apply any configuration changes found.

◆ configureFromFile()

std::tuple< spi::ConfigurationStatus, LogString > log4cxx::DefaultConfigurator::configureFromFile ( const std::vector< LogString > & directories,
const std::vector< LogString > & filenames )
static

Call configure() passing the default repository after calling setConfigurationFileName() with a path composed of an entry in directories and an entry in filenames when the combination identifies an existing file.

Example usage:
std::vector<LogString> directories
{ LOG4CXX_STR(".")
, LOG4CXX_STR("${PROGRAM_FILE_PATH.PARENT_PATH}")
};
std::vector<LogString> filenames
{ LOG4CXX_STR("${PROGRAM_FILE_PATH.STEM}.xml")
, LOG4CXX_STR("${PROGRAM_FILE_PATH.STEM}.properties")
, LOG4CXX_STR("log4cxx.xml")
};
static std::tuple< spi::ConfigurationStatus, LogString > configureFromFile(const std::vector< LogString > &directories, const std::vector< LogString > &filenames)
Call configure() passing the default repository after calling setConfigurationFileName() with a path ...

Using the above example and an executable file named "myapp" installed in the directory "/opt/com.foo/bin", locations are checked in the following order:

  1. "./myapp.xml"
  2. "./myapp.properties"
  3. "./log4cxx.xml"
  4. "/opt/com.foo/bin/myapp.xml"
  5. "/opt/com.foo/bin/myapp.properties"
  6. "/opt/com.foo/bin/log4cxx.xml"

If a file exists but it is not able to be used to configure Log4cxx, the next file in the combinatorial set will be tried until a valid configuration file is found or all values in the combinatorial set have been tried.

Parameters
directoriesThe directories to look in.
filenamesThe names of the files to look for
Returns
a success indicator and the configuration file path that was used (if found).
Examples
com/foo/config4.cpp.

◆ setConfigurationFileName()

LogString log4cxx::DefaultConfigurator::setConfigurationFileName ( const LogString & path)
static

Make path the configuration file used by configure().

Any ${varname} instances in the path value are expanded using either a system environment variable value (if found) otherwise using the map provided by spi::Configurator::properties.

Example usage:
DefaultConfigurator::setConfigurationFileName(LOG4CXX_STR("${PROGRAM_FILE_PATH.PARENT_PATH}/${PROGRAM_FILE_PATH.STEM}.xml"))
static LogString setConfigurationFileName(const LogString &path)
Make path the configuration file used by configure().
Returns
The previous value of LOG4CXX_CONFIGURATION in spi::Configurator::properties or environment variable

◆ setConfigurationWatchSeconds()

int log4cxx::DefaultConfigurator::setConfigurationWatchSeconds ( int seconds)
static

Make seconds the time a background task will delay before checking for a change to the configuration file used by configure().

Example usage:
static int setConfigurationWatchSeconds(int seconds)
Make seconds the time a background task will delay before checking for a change to the configuration ...
Returns
The previous value of LOG4CXX_CONFIGURATION_WATCH_SECONDS in spi::Configurator::properties or environment variable
Examples
com/foo/config4.cpp.

◆ setConfiguratorClass()

LogString log4cxx::DefaultConfigurator::setConfiguratorClass ( const LogString & className)
static

Instantiate an instance of className to process the configuration file used by configure().

Returns
The previous value of LOG4CXX_CONFIGURATOR_CLASS in spi::Configurator::properties or environment variable

The documentation for this class was generated from the following file: