r24908 - in /trunk/liblog-handler-perl: ./ debian/ examples/ lib/Log/ lib/Log/Handler/ t/
rmayorga-guest at users.alioth.debian.org
rmayorga-guest at users.alioth.debian.org
Mon Sep 8 05:39:58 UTC 2008
Author: rmayorga-guest
Date: Mon Sep 8 05:39:55 2008
New Revision: 24908
URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=24908
Log:
* New upstream release
* add LOG_HANDLER_SOCK_TEST var to debian/rules, this enable just
one more test
Added:
trunk/liblog-handler-perl/examples/config-examples.pl
- copied unchanged from r24907, branches/upstream/liblog-handler-perl/current/examples/config-examples.pl
Removed:
trunk/liblog-handler-perl/lib/Log/Handler/Changes.pod
Modified:
trunk/liblog-handler-perl/ChangeLog
trunk/liblog-handler-perl/MANIFEST
trunk/liblog-handler-perl/META.yml
trunk/liblog-handler-perl/README
trunk/liblog-handler-perl/debian/changelog
trunk/liblog-handler-perl/debian/rules
trunk/liblog-handler-perl/examples/benchmark.pl
trunk/liblog-handler-perl/examples/client.pl
trunk/liblog-handler-perl/examples/example.conf
trunk/liblog-handler-perl/examples/example.pl
trunk/liblog-handler-perl/examples/example.props
trunk/liblog-handler-perl/examples/example.yaml
trunk/liblog-handler-perl/examples/layout.pl
trunk/liblog-handler-perl/examples/runtime.pl
trunk/liblog-handler-perl/examples/server.pl
trunk/liblog-handler-perl/lib/Log/Handler.pm
trunk/liblog-handler-perl/lib/Log/Handler/Config.pm
trunk/liblog-handler-perl/lib/Log/Handler/Examples.pod
trunk/liblog-handler-perl/lib/Log/Handler/Levels.pm
trunk/liblog-handler-perl/t/100-config.t
Modified: trunk/liblog-handler-perl/ChangeLog
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/liblog-handler-perl/ChangeLog?rev=24908&op=diff
==============================================================================
--- trunk/liblog-handler-perl/ChangeLog (original)
+++ trunk/liblog-handler-perl/ChangeLog Mon Sep 8 05:39:55 2008
@@ -1,4 +1,11 @@
-0.45 Released at 2008-07-28.
+0.47 Released at 2008-09-04.
+ - Add new config features. Now it's possilbe to add the
+ configuration for the outputs as a array reference.
+ - Add method log() to log with the level as first argument:
+ log($level=>$msg).
+ - Kicked Changes.pm. Not needed any more.
+
+0.46 Released at 2008-07-28.
- Fixed Plugin::YAML. It was created as Plugin::Config::YAML.
- Did some code/example improvements.
Modified: trunk/liblog-handler-perl/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/liblog-handler-perl/MANIFEST?rev=24908&op=diff
==============================================================================
--- trunk/liblog-handler-perl/MANIFEST (original)
+++ trunk/liblog-handler-perl/MANIFEST Mon Sep 8 05:39:55 2008
@@ -2,6 +2,7 @@
ChangeLog
examples/benchmark.pl
examples/client.pl
+examples/config-examples.pl
examples/example.conf
examples/example.pl
examples/example.props
@@ -11,7 +12,6 @@
examples/server.pl
INSTALL
lib/Log/Handler.pm
-lib/Log/Handler/Changes.pod
lib/Log/Handler/Config.pm
lib/Log/Handler/Examples.pod
lib/Log/Handler/Levels.pm
Modified: trunk/liblog-handler-perl/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/liblog-handler-perl/META.yml?rev=24908&op=diff
==============================================================================
--- trunk/liblog-handler-perl/META.yml (original)
+++ trunk/liblog-handler-perl/META.yml Mon Sep 8 05:39:55 2008
@@ -1,6 +1,6 @@
---
name: Log-Handler
-version: 0.46
+version: 0.47
author:
- Jonny Schulz
abstract: Log messages to several outputs.
@@ -30,13 +30,13 @@
provides:
Log::Handler:
file: lib/Log/Handler.pm
- version: 0.46
+ version: 0.47
Log::Handler::Config:
file: lib/Log/Handler/Config.pm
- version: 0.03
+ version: 0.04
Log::Handler::Levels:
file: lib/Log/Handler/Levels.pm
- version: 0.04
+ version: 0.05
Log::Handler::Output:
file: lib/Log/Handler/Output.pm
version: 0.04
Modified: trunk/liblog-handler-perl/README
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/liblog-handler-perl/README?rev=24908&op=diff
==============================================================================
--- trunk/liblog-handler-perl/README (original)
+++ trunk/liblog-handler-perl/README Mon Sep 8 05:39:55 2008
@@ -574,13 +574,13 @@
is_debug()
is_info()
is_notice()
- is_warning()
+ is_warning(), is_warn()
is_error(), is_err()
is_critical(), is_crit()
is_alert()
is_emergency(), is_emerg()
- These thirteen methods could be very useful if you want to kwow if the
+ These twelve methods could be very useful if you want to kwow if the
current level would log the message. All methods returns TRUE if the
current set of "minlevel" and "maxlevel" would log the message and FALSE
if not.
Modified: trunk/liblog-handler-perl/debian/changelog
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/liblog-handler-perl/debian/changelog?rev=24908&op=diff
==============================================================================
--- trunk/liblog-handler-perl/debian/changelog (original)
+++ trunk/liblog-handler-perl/debian/changelog Mon Sep 8 05:39:55 2008
@@ -1,3 +1,11 @@
+liblog-handler-perl (0.47-1) unstable; urgency=low
+
+ * New upstream release
+ * add LOG_HANDLER_SOCK_TEST var to debian/rules, this enable just
+ one more test
+
+ -- Rene Mayorga <rmayorga at debian.org.sv> Sun, 07 Sep 2008 22:59:59 -0600
+
liblog-handler-perl (0.46-1) unstable; urgency=low
* New upstream release
Modified: trunk/liblog-handler-perl/debian/rules
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/liblog-handler-perl/debian/rules?rev=24908&op=diff
==============================================================================
--- trunk/liblog-handler-perl/debian/rules (original)
+++ trunk/liblog-handler-perl/debian/rules Mon Sep 8 05:39:55 2008
@@ -2,7 +2,7 @@
build: build-stamp
build-stamp:
- dh build
+ LOG_HANDLER_SOCK_TEST=1 dh build
touch $@
clean:
Modified: trunk/liblog-handler-perl/examples/benchmark.pl
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/liblog-handler-perl/examples/benchmark.pl?rev=24908&op=diff
==============================================================================
--- trunk/liblog-handler-perl/examples/benchmark.pl (original)
+++ trunk/liblog-handler-perl/examples/benchmark.pl Mon Sep 8 05:39:55 2008
@@ -1,4 +1,29 @@
#!/usr/bin/perl
+
+=head1 AUTHOR
+
+Jonny Schulz <jschulz.cpan(at)bloonix.de>
+
+=head1 DESCRIPTION
+
+Benchmarks... what else could I say...
+
+=head1 POWERED BY
+
+ _ __ ____ ____ __ __ __ __ __
+ | |__| | | | \| |__|\ \/ /
+ | . | | | | | | | | > <
+ |____|__|____|____|__|\__|__|/__/\__\
+
+=head1 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.
+
+=cut
+
use strict;
use warnings;
use Log::Handler;
Modified: trunk/liblog-handler-perl/examples/client.pl
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/liblog-handler-perl/examples/client.pl?rev=24908&op=diff
==============================================================================
--- trunk/liblog-handler-perl/examples/client.pl (original)
+++ trunk/liblog-handler-perl/examples/client.pl Mon Sep 8 05:39:55 2008
@@ -1,4 +1,29 @@
#!/usr/bin/perl
+
+=head1 AUTHOR
+
+Jonny Schulz <jschulz.cpan(at)bloonix.de>
+
+=head1 DESCRIPTION
+
+This is a client example for Log::Handler::Output::Socket.
+
+=head1 POWERED BY
+
+ _ __ ____ ____ __ __ __ __ __
+ | |__| | | | \| |__|\ \/ /
+ | . | | | | | | | | > <
+ |____|__|____|____|__|\__|__|/__/\__\
+
+=head1 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.
+
+=cut
+
use strict;
use warnings;
use Log::Handler;
Modified: trunk/liblog-handler-perl/examples/example.conf
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/liblog-handler-perl/examples/example.conf?rev=24908&op=diff
==============================================================================
--- trunk/liblog-handler-perl/examples/example.conf (original)
+++ trunk/liblog-handler-perl/examples/example.conf Mon Sep 8 05:39:55 2008
@@ -1,8 +1,6 @@
<screen>
- <screen1>
- maxlevel = debug
- minlevel = emerg
- newline = 1
- message_layout = %T %H[%P] [%L] Config::General - %m
- </screen1>
+ maxlevel = debug
+ minlevel = emerg
+ newline = 1
+ message_layout = %T %H[%P] [%L] Config::General - %m
</screen>
Modified: trunk/liblog-handler-perl/examples/example.pl
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/liblog-handler-perl/examples/example.pl?rev=24908&op=diff
==============================================================================
--- trunk/liblog-handler-perl/examples/example.pl (original)
+++ trunk/liblog-handler-perl/examples/example.pl Mon Sep 8 05:39:55 2008
@@ -1,4 +1,30 @@
#!/usr/bin/perl
+
+=head1 AUTHOR
+
+Jonny Schulz <jschulz.cpan(at)bloonix.de>
+
+=head1 DESCRIPTION
+
+With this script you can test if the example configurations
+works.
+
+=head1 POWERED BY
+
+ _ __ ____ ____ __ __ __ __ __
+ | |__| | | | \| |__|\ \/ /
+ | . | | | | | | | | > <
+ |____|__|____|____|__|\__|__|/__/\__\
+
+=head1 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.
+
+=cut
+
use strict;
use warnings;
use Log::Handler;
Modified: trunk/liblog-handler-perl/examples/example.props
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/liblog-handler-perl/examples/example.props?rev=24908&op=diff
==============================================================================
--- trunk/liblog-handler-perl/examples/example.props (original)
+++ trunk/liblog-handler-perl/examples/example.props Mon Sep 8 05:39:55 2008
@@ -1,4 +1,4 @@
-screen.screen2.maxlevel = debug
-screen.screen2.minlevel = emerg
-screen.screen2.newline = 1
-screen.screen2.message_layout = %T %H[%P] [%L] Config::Properties %m
+screen.maxlevel = debug
+screen.minlevel = emerg
+screen.newline = 1
+screen.message_layout = %T %H[%P] [%L] Config::Properties %m
Modified: trunk/liblog-handler-perl/examples/example.yaml
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/liblog-handler-perl/examples/example.yaml?rev=24908&op=diff
==============================================================================
--- trunk/liblog-handler-perl/examples/example.yaml (original)
+++ trunk/liblog-handler-perl/examples/example.yaml Mon Sep 8 05:39:55 2008
@@ -1,7 +1,6 @@
---
screen:
- screen3:
- maxlevel: debug
- minlevel: emerg
- newline: 1
- message_layout: %T %H[%P] [%L] YAML - %m
+ maxlevel: debug
+ minlevel: emerg
+ newline: 1
+ message_layout: %T %H[%P] [%L] YAML - %m
Modified: trunk/liblog-handler-perl/examples/layout.pl
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/liblog-handler-perl/examples/layout.pl?rev=24908&op=diff
==============================================================================
--- trunk/liblog-handler-perl/examples/layout.pl (original)
+++ trunk/liblog-handler-perl/examples/layout.pl Mon Sep 8 05:39:55 2008
@@ -1,4 +1,29 @@
#!/usr/bin/perl
+
+=head1 AUTHOR
+
+Jonny Schulz <jschulz.cpan(at)bloonix.de>
+
+=head1 DESCRIPTION
+
+This script shows you examples for all patterns.
+
+=head1 POWERED BY
+
+ _ __ ____ ____ __ __ __ __ __
+ | |__| | | | \| |__|\ \/ /
+ | . | | | | | | | | > <
+ |____|__|____|____|__|\__|__|/__/\__\
+
+=head1 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.
+
+=cut
+
use strict;
use warnings;
use Log::Handler;
Modified: trunk/liblog-handler-perl/examples/runtime.pl
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/liblog-handler-perl/examples/runtime.pl?rev=24908&op=diff
==============================================================================
--- trunk/liblog-handler-perl/examples/runtime.pl (original)
+++ trunk/liblog-handler-perl/examples/runtime.pl Mon Sep 8 05:39:55 2008
@@ -1,4 +1,29 @@
#!/usr/bin/perl
+
+=head1 AUTHOR
+
+Jonny Schulz <jschulz.cpan(at)bloonix.de>
+
+=head1 DESCRIPTION
+
+This script shows you an example for the runtime patterns.
+
+=head1 POWERED BY
+
+ _ __ ____ ____ __ __ __ __ __
+ | |__| | | | \| |__|\ \/ /
+ | . | | | | | | | | > <
+ |____|__|____|____|__|\__|__|/__/\__\
+
+=head1 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.
+
+=cut
+
use strict;
use warnings;
use Log::Handler;
Modified: trunk/liblog-handler-perl/examples/server.pl
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/liblog-handler-perl/examples/server.pl?rev=24908&op=diff
==============================================================================
--- trunk/liblog-handler-perl/examples/server.pl (original)
+++ trunk/liblog-handler-perl/examples/server.pl Mon Sep 8 05:39:55 2008
@@ -1,4 +1,29 @@
#!/usr/bin/perl
+
+=head1 AUTHOR
+
+Jonny Schulz <jschulz.cpan(at)bloonix.de>
+
+=head1 DESCRIPTION
+
+This is a server example for Log::Handler::Output::Socket.
+
+=head1 POWERED BY
+
+ _ __ ____ ____ __ __ __ __ __
+ | |__| | | | \| |__|\ \/ /
+ | . | | | | | | | | > <
+ |____|__|____|____|__|\__|__|/__/\__\
+
+=head1 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.
+
+=cut
+
use strict;
use warnings;
use IO::Socket::INET;
Modified: trunk/liblog-handler-perl/lib/Log/Handler.pm
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/liblog-handler-perl/lib/Log/Handler.pm?rev=24908&op=diff
==============================================================================
--- trunk/liblog-handler-perl/lib/Log/Handler.pm (original)
+++ trunk/liblog-handler-perl/lib/Log/Handler.pm Mon Sep 8 05:39:55 2008
@@ -601,7 +601,7 @@
=item B<is_notice()>
-=item B<is_warning()>
+=item B<is_warning()>, B<is_warn()>
=item B<is_error()>, B<is_err()>
@@ -613,7 +613,7 @@
=back
-These thirteen methods could be very useful if you want to kwow if the current
+These twelve methods could be very useful if you want to kwow if the current
level would log the message. All methods returns TRUE if the current set
of C<minlevel> and C<maxlevel> would log the message and FALSE if not.
@@ -849,7 +849,7 @@
use Log::Handler::Pattern;
use base qw(Log::Handler::Levels);
-our $VERSION = '0.46';
+our $VERSION = '0.47';
our $ERRSTR = '';
# $TRACE and $CALLER_LEVEL are both used as global
Modified: trunk/liblog-handler-perl/lib/Log/Handler/Config.pm
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/liblog-handler-perl/lib/Log/Handler/Config.pm?rev=24908&op=diff
==============================================================================
--- trunk/liblog-handler-perl/lib/Log/Handler/Config.pm (original)
+++ trunk/liblog-handler-perl/lib/Log/Handler/Config.pm Mon Sep 8 05:39:55 2008
@@ -89,12 +89,15 @@
<logger>
<file>
- <mylog>
- filename = file.log
- minlevel = 0
- maxlevel = 7
- </mylog>
+ filename = file.log
+ minlevel = emerg
+ maxlevel = warning
</file>
+
+ <screen>
+ minlevel = emerg
+ maxlevel = debug
+ </screen>
</logger>
<another_script_config>
@@ -122,13 +125,6 @@
$log->config( config => $config{logger} );
-Note that the section C<mylog> is used as an C<alias>. Later you access the
-output with
-
- my $file_output = $log->output('mylog');
-
- $file_output->log(message => 'your message');
-
=back
=head1 PLUGINS
@@ -139,88 +135,123 @@
=head1 EXAMPLES
-=head2 Config structure
-
-For each output it must exist an own section. Here a example as hash:
-
- my %config = (
-
- # the configuration for a file
-
+=head2 Config structures
+
+A very simple configuration looks like:
+
+ $log->config(config => {
file => {
- foo => {
+ alias => 'file1',
+ filename => 'file1.log',
+ maxlevel => 'info',
+ minlevel => 'warn',
+ },
+ screen => {
+ alias => 'screen1',
+ maxlevel => 'debug',
+ minlevel => 'emerg',
+ }
+ });
+
+Now, if you want to add another file-output then you can pass the outputs
+with a array reference:
+
+ $log->config(config => {
+ file => [
+ {
+ alias => 'file1,
filename => 'file1.log',
maxlevel => 'info',
minlevel => 'warn',
},
- bar => {
+ {
+ alias => 'file2',
filename => 'file2.log',
maxlevel => 'error',
minlevel => 'emergency',
}
- }
-
- # the configuration for email
-
- email => {
- baz =>
- host => 'foo.example',
- from => 'me at me.example',
- to => 'you at foo.example',
- maxlevel => 'error',
- minlevel => 'emergency',
- },
-
- # and_so_on ...
- }
- );
-
-You can store your configuration to a file and loads it. There are different
-config plugins available.
-
-=head2 A default section
-
-It's possible to define a section called C<default> for each output. This
-options are used as default if this options are not set. Example:
-
- my %config = (
- # the configuration for a file
+ ],
+ screen => {
+ alias => 'screen1',
+ maxlevel => 'debug',
+ minlevel => 'emerg',
+ },
+ });
+
+It's also possible to pass the outputs as a hash reference.
+The hash keys "file1" and "file2" will be used as aliases.
+
+ $log->config(config => {
file => {
- default => {
- mode => 'append',
- },
- foo => {
+ file1 => {
filename => 'file1.log',
maxlevel => 'info',
minlevel => 'warn',
},
- bar => {
+ file2 => {
filename => 'file2.log',
maxlevel => 'error',
minlevel => 'emergency',
+ }
+ },
+ screen => {
+ alias => 'screen1',
+ maxlevel => 'debug',
+ minlevel => 'emerg',
+ },
+ });
+
+If you pass the configuration with the alias as a hash key then
+it's also possible to pass a section called "section". The options
+from this section will be used as defaults.
+
+ $log->config(config => {
+ file => {
+ default => { # defaults for all file-outputs
+ newline => 1,
+ mode => 'append',
},
- baz => {
- filename => 'file3.log',
- maxlevel => 'debug',
- minlevel => 'debug',
- mode => 'trunc',
+ file1 => {
+ filename => 'file1.log',
+ maxlevel => 'info',
+ minlevel => 'warn',
},
- },
- # the configuration for dbi
- dbi => {
- default => { ... }
- }
- );
-
-The option C<mode> is set to C<append> for the log file C<file1.log> and
-C<file2.log>. The configuration for C<file3.log> will be set to C<trunc>.
+ file2 => {
+ filename => 'file2.log',
+ maxlevel => 'error',
+ minlevel => 'emergency',
+ }
+ },
+ screen => {
+ alias => 'screen1',
+ maxlevel => 'debug',
+ minlevel => 'emerg',
+ },
+ });
=head2 Examples for the config plugins
=head3 Config::General
<file>
- <mylog>
+ alias = file1
+ fileopen = 1
+ reopen = 1
+ permissions = 0640
+ maxlevel = info
+ minlevel = warn
+ mode = append
+ timeformat = %b %d %H:%M:%S
+ debug_mode = 2
+ filename = example.log
+ message_layout = '%T %H[%P] [%L] %S: %m'
+ newline = 1
+ </file>
+
+Or
+
+ <file>
+ <file1>
fileopen = 1
reopen = 1
permissions = 0640
@@ -232,14 +263,31 @@
filename = example.log
message_layout = '%T %H[%P] [%L] %S: %m'
newline = 1
- </mylog>
+ </file1>
</file>
=head3 YAML
---
file:
- mylog:
+ alias: file1
+ debug_mode: 2
+ filename: example.log
+ fileopen: 1
+ maxlevel: info
+ minlevel: warn
+ mode: append
+ newline: 1
+ permissions: 0640
+ message_layout: '%T %H[%P] [%L] %S: %m'
+ reopen: 1
+ timeformat: '%b %d %H:%M:%S'
+
+Or
+
+ ---
+ file:
+ file1:
debug_mode: 2
filename: example.log
fileopen: 1
@@ -254,163 +302,33 @@
=head3 Config::Properties
- file.mylog.reopen = 1
- file.mylog.fileopen = 1
- file.mylog.maxlevel = info
- file.mylog.minlevel = warn
- file.mylog.permissions = 0640
- file.mylog.mode = append
- file.mylog.timeformat = %b %d %H:%M:%S
- file.mylog.debug_mode = 2
- file.mylog.filename = example.log
- file.mylog.newline = 1
- file.mylog.message_layout = '%T %H[%P] [%L] %S: %m'
-
-=head2 Load the config from a certain section
-
-The config (Config::General)
-
- <output>
- <file>
- <default>
- newline = 1
- permissions = 0640
- timeformat = %b %d %H:%M:%S
- fileopen = 1
- reopen = 1
- mode = append
- message_layout = "%T %H[%P] [%L] %S: %m"
- debug_mode = 2
- </default>
-
- <common>
- filename = example.log
- maxlevel = info
- minlevel = warn
- </common>
-
- <error>
- filename = example-error.log
- maxlevel = warn
- minlevel = emergency
- </error>
-
- <debug>
- filename = example-debug.log
- maxlevel = debug
- minlevel = debug
- </debug>
- </file>
- </output>
-
-Load the config
-
- $log->config(
- config => 'file.conf',
- section => 'output',
- );
-
-=head2 Simple configuration without a certain section
-
-The config (Config::General)
-
- <file>
- <default>
- newline = 1
- permissions = 0640
- timeformat = %b %d %H:%M:%S
- fileopen = 1
- reopen = 1
- mode = append
- message_layout = "%T %H[%P] [%L] %S: $m"
- debug_mode = 2
- </default>
-
- <common>
- filename = example.log
- maxlevel = info
- minlevel = warn
- </common>
-
- <error>
- filename = example-error.log
- maxlevel = warn
- minlevel = emergency
- </error>
-
- <debug>
- filename = example-debug.log
- maxlevel = debug
- minlevel = debug
- </debug>
- </file>
-
-Load the config
-
- $log->config(config => 'file.conf');
-
-=head2 The config as hash
-
- $log->config(
- config => {
- file => {
- default => {
- newline => 1,
- permissions => '0640',
- timeformat => '%b %d %H:%M:%S',
- fileopen => 1,
- reopen => 1,
- mode => 'append',
- message_layout => '%T %H[%P] [%L] %S: %m',
- debug_mode => 2,
- },
- common => {
- filename => 'example.log',
- maxlevel => 'info',
- minlevel => 'warn',
- },
- error => {
- filename => 'example-error.log',
- maxlevel => 'warn',
- minlevel => 'emergency',
- },
- debug => {
- filename => 'example-debug.log',
- maxlevel => 'debug',
- minlevel => 'debug',
- }
- }
- }
- );
-
-=head2 Configuration for different outputs
-
- <output>
- <file>
- <default>
- newline = 1
- permissions = 0640
- timeformat = %b %d %H:%M:%S
- fileopen = 1
- reopen = 1
- mode = append
- message_layout = "%T %H[%P] [%L] %S: %m"
- debug_mode = 2
- </default>
-
- <common>
- filename = example.log
- maxlevel = info
- minlevel = warn
- </common>
-
- <error>
- filename = example-error.log
- maxlevel = warn
- minlevel = emergency
- </error>
- </file>
- </output>
+ file.alias = file1
+ file.reopen = 1
+ file.fileopen = 1
+ file.maxlevel = info
+ file.minlevel = warn
+ file.permissions = 0640
+ file.mode = append
+ file.timeformat = %b %d %H:%M:%S
+ file.debug_mode = 2
+ file.filename = example.log
+ file.newline = 1
+ file.message_layout = '%T %H[%P] [%L] %S: %m'
+
+Or
+
+ file.file1.alias = file1
+ file.file1.reopen = 1
+ file.file1.fileopen = 1
+ file.file1.maxlevel = info
+ file.file1.minlevel = warn
+ file.file1.permissions = 0640
+ file.file1.mode = append
+ file.file1.timeformat = %b %d %H:%M:%S
+ file.file1.debug_mode = 2
+ file.file1.filename = example.log
+ file.file1.newline = 1
+ file.file1.message_layout = '%T %H[%P] [%L] %S: %m'
=head1 PREREQUISITES
@@ -445,7 +363,7 @@
use strict;
use warnings;
-our $VERSION = '0.03';
+our $VERSION = '0.04';
use Carp;
use File::Spec;
@@ -453,61 +371,99 @@
use UNIVERSAL::require;
sub config {
- my $class = shift;
- my $params = $class->_validate(@_);
+ my $self = shift;
+ my $params = $self->_validate(@_);
+ my $config = $self->_get_config($params);
+
+ if (ref($config) ne 'HASH') {
+ croak "Bad config structure!";
+ }
+
+ # Structure:
+ # $log_config{file} = [ \%a, \%b, \%c ]
+ # $log_config{dbi} = [ \%a, \%b, \%c ]
+ my %log_config;
+
+ while (my ($type, $output) = each %$config) {
+ my $ref = ref($output);
+
+ if ($ref eq 'HASH') {
+ push @{$log_config{$type}}, $self->_get_hash_config($output);
+ } elsif ($ref eq 'ARRAY') {
+ push @{$log_config{$type}}, $self->_get_array_config($output);
+ } else {
+ croak "Bad config structure for '$type'";
+ }
+ }
+
+ return \%log_config;
+}
+
+#
+# private stuff
+#
+
+sub _get_config {
+ my ($self, $params) = @_;
+ my $config = ();
my $plugin = $params->{plugin};
- my ($config, %all_configs);
if (ref($params->{config})) {
$config = $params->{config};
} elsif ($params->{config}) {
- $plugin->require or Carp::croak "unable to load plugin '$plugin'";
+ $plugin->require or croak "Unable to load plugin '$plugin'";
$config = $plugin->get_config($params->{config});
}
- $class->_is_hash('main', $config);
-
if ($params->{section}) {
- $class->_is_hash($params->{section}, $config->{ $params->{section} });
- $config = $config->{ $params->{section} };
- }
-
- while ( my ($type, $type_config) = each %$config ) {
- $class->_is_hash($type, $type_config);
- my %default = ();
-
- if ($type_config->{default}) {
- $class->_is_hash('default', $type_config->{default});
- %default = (%{ $type_config->{default} });
+ return $config->{ $params->{section} };
+ }
+
+ return $config;
+}
+
+sub _get_hash_config {
+ my ($self, $config) = @_;
+ my @config = ();
+ my %default = ();
+
+ if (exists $config->{default}) {
+ %default = %{ delete $config->{default} };
+ }
+
+ while (my ($alias, $param) = each %$config) {
+ if (ref($param) ne 'HASH') {
+ push @config, $config;
+ last;
}
-
- # Structure:
- # $all_configs{file} = [ \%a, \%b, \%c ]
- # $all_configs{dbi} = [ \%a, \%b, \%c ]
-
- while ( my ($name, $log_config) = each %$type_config ) {
- $class->_is_hash($name, $log_config);
- next if $name eq 'default';
- my %new_config = (%default, %$log_config, alias => $name);
- push @{$all_configs{$type}}, \%new_config;
- }
- }
-
- return \%all_configs;
+ $param->{alias} = $alias;
+ my %config = (%default, %$param);
+ push @config, \%config;
+ }
+
+ return @config;
}
-#
-# private stuff
-#
+sub _get_array_config {
+ my ($self, $config) = @_;
+ my @config = ();
+
+ foreach my $params (@$config) {
+ push @config, $params;
+ }
+
+ return @config;
+}
sub _validate {
- my $class = shift;
+ my $self = shift;
my %options = Params::Validate::validate(@_, {
config => {
type => Params::Validate::SCALAR
| Params::Validate::HASHREF
| Params::Validate::ARRAYREF,
+ optional => 1,
},
plugin => {
type => Params::Validate::SCALAR,
@@ -519,12 +475,14 @@
},
});
- if (ref($options{config}) eq 'ARRAY') {
- $options{config} = File::Spec->catfile(@{$options{config}});
- }
-
- if (!$options{plugin}) {
- if (!ref($options{config})) {
+ my $ref = ref($options{config});
+
+ if ($ref ne 'HASH') {
+ if ($ref eq 'ARRAY') {
+ $options{config} = File::Spec->catfile(@{$options{config}});
+ }
+
+ if (!$options{plugin}) {
if ($options{config} =~ /\.ya{0,1}ml\z/) {
$options{plugin} = 'Log::Handler::Plugin::YAML';
} elsif ($options{config} =~ /\.(?:props|jc(?:onf|fg))\z/) {
@@ -538,11 +496,4 @@
return \%options;
}
-sub _is_hash {
- my ($self, $name, $ref) = @_;
- if (ref($ref) ne 'HASH') {
- Carp::croak "bad config structure! Config name '$name' missplaced";
- }
-}
-
1;
Modified: trunk/liblog-handler-perl/lib/Log/Handler/Examples.pod
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/liblog-handler-perl/lib/Log/Handler/Examples.pod?rev=24908&op=diff
==============================================================================
--- trunk/liblog-handler-perl/lib/Log/Handler/Examples.pod (original)
+++ trunk/liblog-handler-perl/lib/Log/Handler/Examples.pod Mon Sep 8 05:39:55 2008
@@ -324,7 +324,37 @@
=head1 CONFIG
-File: file.conf
+Examples with Config::General.
+
+ <file>
+ alias = common
+ filename = example.log
+ maxlevel = info
+ minlevel = warn
+ </file>
+
+ <file>
+ alias = error
+ filename = example-error.log
+ maxlevel = warn
+ minlevel = emergency
+ </file>
+
+ <file>
+ alias = debug
+ filename = example-debug.log
+ maxlevel = debug
+ minlevel = debug
+ </file>
+
+ <screen>
+ log_to = STDERR
+ dump = 1
+ maxlevel = debug
+ minlevel = debug
+ </screen>
+
+Or
<file>
<default>
Modified: trunk/liblog-handler-perl/lib/Log/Handler/Levels.pm
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/liblog-handler-perl/lib/Log/Handler/Levels.pm?rev=24908&op=diff
==============================================================================
--- trunk/liblog-handler-perl/lib/Log/Handler/Levels.pm (original)
+++ trunk/liblog-handler-perl/lib/Log/Handler/Levels.pm Mon Sep 8 05:39:55 2008
@@ -115,6 +115,23 @@
as first argument:
$log->die(fatal => 'an emergency error here');
+
+=item B<log()>
+
+With this method it's possible to log messages with the log level as
+first argument:
+
+ $log->log(info => 'an info message');
+
+Is the same like
+
+ $log->info('an info message');
+
+and
+
+ $log->log('an info message');
+
+If you log without a level then the default level is C<info>.
=back
@@ -158,7 +175,7 @@
use Carp;
use Data::Dumper;
-our $VERSION = '0.04';
+our $VERSION = '0.05';
my %LEVELS_BY_ROUTINE = (
debug => 'DEBUG',
@@ -221,6 +238,16 @@
} # end "no strict 'refs'" block
}
+sub log {
+ my $self = shift;
+ my $level = @_ > 1 ? lc(shift) : 'info';
+ if (!exists $LEVELS_BY_ROUTINE{$level}) {
+ $level = 'info';
+ }
+ local $Log::Handler::CALLER_LEVEL = 1;
+ return $self->$level(@_);
+}
+
sub trace {
my $self = shift;
my $level = @_ > 1 ? lc(shift) : 'debug';
Modified: trunk/liblog-handler-perl/t/100-config.t
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/liblog-handler-perl/t/100-config.t?rev=24908&op=diff
==============================================================================
--- trunk/liblog-handler-perl/t/100-config.t (original)
+++ trunk/liblog-handler-perl/t/100-config.t Mon Sep 8 05:39:55 2008
@@ -1,6 +1,6 @@
use strict;
use warnings;
-use Test::More tests => 8;
+use Test::More tests => 15;
use Log::Handler;
my %config = (
@@ -13,41 +13,82 @@
debug_mode => 2,
fileopen => 0,
},
- common => {
+ file1 => {
filename => 'foo',
maxlevel => 'info',
- minlevel => 'info',
newline => 0,
+ priority => 1,
}
- }
+ },
+ screen => [
+ {
+ alias => 'screen1',
+ dump => 1,
+ newline => 1,
+ priority => 2,
+ maxlevel => 'info',
+ },
+ {
+ alias => 'screen2',
+ dump => 0,
+ newline => 0,
+ priority => 3,
+ maxlevel => 'info',
+ }
+ ]
);
my $log = Log::Handler->new();
$log->config(config => \%config);
-my $options_handler = shift @{$log->{levels}->{INFO}};
-my $options_file = $options_handler->{output};
+my %opts;
+$opts{handler}{file1} = shift @{$log->{levels}->{INFO}};
+$opts{handler}{screen1} = shift @{$log->{levels}->{INFO}};
+$opts{handler}{screen2} = shift @{$log->{levels}->{INFO}};
+$opts{output}{file1} = $log->output('file1');
+$opts{output}{screen1} = $log->output('screen1');
+$opts{output}{screen2} = $log->output('screen2');
-my %compare_file = (
- filename => 'foo',
- fileopen => 0,
+my %cmp = (
+ output => {
+ file1 => {
+ filename => 'foo',
+ fileopen => 0,
+ },
+ screen1 => {
+ dump => 1,
+ },
+ screen2 => {
+ dump => 0,
+ }
+ },
+ handler => {
+ file1 => {
+ newline => 0,
+ timeformat => '%b %d %H:%M:%S',
+ message_layout => '%T %H[%P] [%L] %S: %m',
+ debug_mode => 2,
+ maxlevel => 6,
+ },
+ screen1 => {
+ newline => 1,
+ priority => 2,
+ maxlevel => 6,
+ },
+ screen2 => {
+ newline => 0,
+ priority => 3,
+ maxlevel => 6,
+ }
+ }
);
-my %compare_handler = (
- newline => 0,
- timeformat => '%b %d %H:%M:%S',
- message_layout => '%T %H[%P] [%L] %S: %m',
- debug_mode => 2,
- maxlevel => 6,
- minlevel => 6,
-);
-
-while (my ($k, $v) = each %compare_file) {
- my $ret = exists $options_file->{$k} && $options_file->{$k} eq $v;
- ok($ret, "checking option $k ($v:$options_file->{$k})");
+foreach my $x (qw/handler output/) {
+ foreach my $y (qw/file1 screen1 screen2/) {
+ foreach my $k (keys %{$cmp{$x}{$y}}) {
+ my $cmp_val = $cmp{$x}{$y}{$k};
+ my $opt_val = defined $opts{$x}{$y}{$k} ? $opts{$x}{$y}{$k} : 'n/a';
+ ok($cmp_val eq $opt_val, "checking config $x:$y:$k ($cmp_val:$opt_val)");
+ }
+ }
}
-
-while (my ($k, $v) = each %compare_handler) {
- my $ret = exists $options_handler->{$k} && $options_handler->{$k} eq $v;
- ok($ret, "checking option $k ($v:$options_handler->{$k})");
-}
More information about the Pkg-perl-cvs-commits
mailing list