NAME
Log::Handler::Config - A simple config loader.
SYNOPSIS
my $log = Log::Handler->new;
$log->config(filename => 'file.conf');
DESCRIPTION
This module makes it possible to load the configuration for the Log::Handler.
METHODS
config()
With this method it's possible to load a configuration for your logger.
If your configuration contains a default section then this parameters are used for all other log files. Example:
<default>
mode = append
</default>
<file1>
filename = file1.log
</file2>
<file2>
filename = file2.log
</file2>
<file3>
filename = file3.log
mode = trunc
</file3>
The option mode is set for file1.log and file2.log to append, for file3.log it's set to trunc.
filename
The configuration file.
plugin
The plugin you want to use to load the configuration file. There are 3 plugins available:
Config::General
Config::Properties
YAML
section
Load the logger configuration from a main section. Example:
<Log::Handler>
<log_all>
filename = file.log
minlevel = 0
maxlevel = 7
</mylog>
</Log::Handler>
<Another_Script_Config>
foo = bar
</Another_Script_Config>
Now you just want to load the the section Log::Handler. You can do this with
$log->config(
filename => 'file.conf',
section => 'logger',
);
# or if you got the configuration already
$log->config(
config => $config,
section => 'logger',
);
config
With this option you can pass a configuration that you got already.
PLUGINS
Config::General
Config::General - inspired by the well known apache config format
Config::Properties - Java-style property files
YAML - optimized for human readability
EXAMPLES
Load from a section
The config (Config::General)
<logger>
<default>
newline = 1
permissions = 0640
timeformat = %b %d %H:%M:%S
fileopen = 1
reopen = 1
mode = append
prefix = "%T %H[%P] [%L] %S: "
trace = 0
debug_mode = 2
</default>
<common>
filename = example.log
maxlevel = info
minlevel = warn
</common>
<error>
filename = example-error.log
maxlevel = warn
minlevel = emergency
trace = 1
</error>
<debug>
filename = example-debug.log
maxlevel = debug
minlevel = debug
</debug>
</logger>
Load the config
$log->config(
filename => 'file.conf',
section => 'Log::Handler',
plugin => 'Config::General',
);
Simple configuration without a main section
The config (Config::General)
<default>
newline = 1
permissions = 0640
timeformat = %b %d %H:%M:%S
fileopen = 1
reopen = 1
mode = append
prefix = "%T %H[%P] [%L] %S: "
trace = 0
debug_mode = 2
</default>
<common>
filename = example.log
maxlevel = info
minlevel = warn
</common>
<error>
filename = example-error.log
maxlevel = warn
minlevel = emergency
trace = 1
</error>
<debug>
filename = example-debug.log
maxlevel = debug
minlevel = debug
</debug>
Load the config
$log->config(
filename => 'file.conf',
section => 'Log::Handler',
plugin => 'Config::General',
);
The config as hash
$log->config(
config => {
default => {
newline => 1,
permissions => '0640',
timeformat => '%b %d %H:%M:%S',
fileopen => 1,
reopen => 1,
mode => 'append
prefix => '%T %H[%P] [%L] %S: ',
trace => 0,
debug_mode => 2,
},
common => {
filename => 'example.log',
maxlevel => 'info',
minlevel => 'warn',
},
error => {
filename => 'example-error.log',
maxlevel => 'warn',
minlevel => 'emergency',
trace => 1,
},
debug => {
filename => 'example-debug.log',
maxlevel => 'debug',
minlevel => 'debug',
},
}
);
PREREQUISITES
Params::Validate - to validate parameters
UNIVERSAL::require - to load plugins
Carp - to croak on errors
EXPORTS
No exports.
REPORT BUGS
Please report all bugs to <jschulz.cpan(at)bloonix.de>.
AUTHOR
Jonny Schulz <jschulz.cpan(at)bloonix.de>.
COPYRIGHT
Copyright (C) 2007 by Jonny Schulz. All rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.