Log::Handler::Config - A simple config loader.
my $log = Log::Handler->new; $log->config(filename => 'file.conf');
This module makes it possible to load the configuration for the Log::Handler.
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
<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.
mode
file1.log
file2.log
append
file3.log
trunc
The configuration file.
The plugin you want to use to load the configuration file. There are 3 plugins available:
Config::General Config::Properties YAML
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::Handler
$log->config( filename => 'file.conf', section => 'logger', ); # or if you got the configuration already $log->config( config => $config, section => 'logger', );
With this option you can pass a configuration that you got already.
Config::General - inspired by the well known apache config format Config::Properties - Java-style property files YAML - optimized for human readability
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', );
<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>
$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', }, } );
Carp Params::Validate UNIVERSAL::require
No exports.
Please report all bugs to <jschulz.cpan(at)bloonix.de>.
Jonny Schulz <jschulz.cpan(at)bloonix.de>.
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.
To install Log::Handler, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Log::Handler
CPAN shell
perl -MCPAN -e shell install Log::Handler
For more information on module installation, please visit the detailed CPAN module installation guide.