r27505 - in /trunk/liblog-handler-perl: ./ debian/ examples/ examples/benchmark/ examples/config/ examples/filter/ examples/layout/ examples/logger/ examples/socket/ lib/Log/ lib/Log/Handler/ t/
ansgar-guest at users.alioth.debian.org
ansgar-guest at users.alioth.debian.org
Sun Nov 30 17:03:17 UTC 2008
Author: ansgar-guest
Date: Sun Nov 30 17:03:14 2008
New Revision: 27505
URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=27505
Log:
* New upstream release.
* Add myself to Uploaders.
Added:
trunk/liblog-handler-perl/examples/benchmark/
- copied from r27504, branches/upstream/liblog-handler-perl/current/examples/benchmark/
trunk/liblog-handler-perl/examples/config/
- copied from r27504, branches/upstream/liblog-handler-perl/current/examples/config/
trunk/liblog-handler-perl/examples/filter/
- copied from r27504, branches/upstream/liblog-handler-perl/current/examples/filter/
trunk/liblog-handler-perl/examples/layout/
- copied from r27504, branches/upstream/liblog-handler-perl/current/examples/layout/
trunk/liblog-handler-perl/examples/logger/
- copied from r27504, branches/upstream/liblog-handler-perl/current/examples/logger/
trunk/liblog-handler-perl/examples/socket/
- copied from r27504, branches/upstream/liblog-handler-perl/current/examples/socket/
trunk/liblog-handler-perl/t/018-handler-logger.t
- copied unchanged from r27504, branches/upstream/liblog-handler-perl/current/t/018-handler-logger.t
Removed:
trunk/liblog-handler-perl/examples/benchmark.pl
trunk/liblog-handler-perl/examples/client.pl
trunk/liblog-handler-perl/examples/config-examples.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.log
trunk/liblog-handler-perl/examples/server.pl
Modified:
trunk/liblog-handler-perl/ChangeLog
trunk/liblog-handler-perl/INSTALL
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/control
trunk/liblog-handler-perl/lib/Log/Handler.pm
trunk/liblog-handler-perl/lib/Log/Handler/Examples.pod
trunk/liblog-handler-perl/lib/Log/Handler/Output.pm
Modified: trunk/liblog-handler-perl/ChangeLog
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/liblog-handler-perl/ChangeLog?rev=27505&op=diff
==============================================================================
--- trunk/liblog-handler-perl/ChangeLog (original)
+++ trunk/liblog-handler-perl/ChangeLog Sun Nov 30 17:03:14 2008
@@ -1,3 +1,9 @@
+0.50 Released at 2008-11-27.
+ - Added the functionality to create a application logger.
+ New functions are create_logger and get_logger.
+ - Added option expect_caller, what is the opposite of
+ option filter_caller.
+
0.49 Released at 2008-11-16.
- Added patterns %U and %G (user, group).
- Fixed a bug in Socket.pm. If the server gone then
Modified: trunk/liblog-handler-perl/INSTALL
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/liblog-handler-perl/INSTALL?rev=27505&op=diff
==============================================================================
--- trunk/liblog-handler-perl/INSTALL (original)
+++ trunk/liblog-handler-perl/INSTALL Sun Nov 30 17:03:14 2008
@@ -4,8 +4,8 @@
make
make test
-"make test" do some tests. If you get error messages then you shouldn't install the module.
-Otherwise your last step is:
+"make test" do some tests. If you get error messages then
+you shouldn't install the module. Otherwise your last step is:
make install
Modified: trunk/liblog-handler-perl/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/liblog-handler-perl/MANIFEST?rev=27505&op=diff
==============================================================================
--- trunk/liblog-handler-perl/MANIFEST (original)
+++ trunk/liblog-handler-perl/MANIFEST Sun Nov 30 17:03:14 2008
@@ -1,16 +1,19 @@
Build.PL
ChangeLog
-examples/benchmark.pl
-examples/client.pl
-examples/config-examples.pl
-examples/example.conf
-examples/example.pl
-examples/example.props
-examples/example.yaml
-examples/layout.pl
-examples/runtime.pl
-examples/server.log
-examples/server.pl
+examples/benchmark/benchmark.pl
+examples/config/example.conf
+examples/config/example.pl
+examples/config/example.props
+examples/config/example.yaml
+examples/filter/extended_filter.pl
+examples/filter/filter_caller.pl
+examples/filter/filter_message.pl
+examples/layout/layout.pl
+examples/layout/runtime.pl
+examples/logger/myapp.pl
+examples/logger/MyApp.pm
+examples/socket/client.pl
+examples/socket/server.pl
INSTALL
lib/Log/Handler.pm
lib/Log/Handler/Config.pm
@@ -45,6 +48,7 @@
t/015-handler-filter-message.t
t/016-handler-alias.t
t/017-handler-special-levels.t
+t/018-handler-logger.t
t/020-output-forward.t
t/030-output-file.t
t/040-output-email.t
Modified: trunk/liblog-handler-perl/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/liblog-handler-perl/META.yml?rev=27505&op=diff
==============================================================================
--- trunk/liblog-handler-perl/META.yml (original)
+++ trunk/liblog-handler-perl/META.yml Sun Nov 30 17:03:14 2008
@@ -1,6 +1,6 @@
---
name: Log-Handler
-version: 0.49
+version: 0.50
author:
- Jonny Schulz
abstract: Log messages to several outputs.
@@ -31,7 +31,7 @@
provides:
Log::Handler:
file: lib/Log/Handler.pm
- version: 0.49
+ version: 0.50
Log::Handler::Config:
file: lib/Log/Handler/Config.pm
version: 0.04
Modified: trunk/liblog-handler-perl/README
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/liblog-handler-perl/README?rev=27505&op=diff
==============================================================================
--- trunk/liblog-handler-perl/README (original)
+++ trunk/liblog-handler-perl/README Sun Nov 30 17:03:14 2008
@@ -14,7 +14,27 @@
newline => 1,
});
- $log->warning("a warinng here");
+ $log->warning("warn message");
+
+ Or
+
+ # init myapp logger with accessor LOG
+ package MyApp;
+ use Log::Handler myapp => 'LOG';
+
+ LOG->add(screen => { maxlevel => 'info' });
+ LOG->info("info message");
+
+ # import myapp logger with accessor LOG
+ package MyApp::Foo;
+ use Log::Handler myapp => 'LOG';
+ LOG->info("info message from MyApp::Foo");
+
+ # get myapp logger with get_logger()
+ package MyApp::Bar;
+ use Log::Handler;
+ my $log = Log::Handler->get_logger('myapp');
+ $log->info("info message from MyApp::Bar");
DESCRIPTION
The "Log::Handler" is a object oriented handler for logging, tracing and
@@ -343,9 +363,9 @@
$log->add(screen => {
maxlevel => 'info',
newline => 1,
- filter_caller => qr/^Foo::Bar$/,
+ filter_caller => qr/^Foo::Bar\z/,
# or
- # filter_caller => '^Foo::Bar$',
+ # filter_caller => '^Foo::Bar\z',
});
package Foo::Bar;
@@ -357,6 +377,13 @@
1;
This would only log the message from the package "Foo::Bar".
+
+ except_caller
+ This options is just the opposite of "filter_caller".
+
+ If you want to log messages from all callers but "Foo::Bar":
+
+ except_caller => qr/^Foo::Bar\z/
alias
You can set an alias if you want to get the output object later.
@@ -715,6 +742,82 @@
Note: valid character for the key name are: "[%\w\-\.]+"
+ create_logger()
+ "create_logger()" is the same like "new()" but it creates a global
+ logger.
+
+ my $log = Log::Handler->create_logger('myapp');
+
+ If you want to create more than one object you can call
+
+ my @logger = Log::Handler->create_logger('myapp1', 'myapp2', ...);
+
+ get_logger()
+ With "get_logger()" it's possible to get a logger that was created with
+ "create_logger()" or with
+
+ use Log::Handler 'myapp';
+
+ Just call
+
+ my $log = Log::Handler->get_logger('myapp');
+
+ Or
+
+ my @logger = Log::Handler->create_logger('myapp1', 'myapp2', ...);
+
+GLOBAL LOG HANDLER
+ Since version 0.50 it's possible to define a application logger. This
+ means to create a "Log::Handler" object and import it into all modules
+ of your program.
+
+ use Log::Handler alias => accessor;
+
+ The accessor is created into the namespace of the caller and referenced
+ to the alias.
+
+ If the alias doesn't exists then a new "Log::Handler" object will be
+ created.
+
+ If no acesseor is set then no accessor is exported into the namespace of
+ the caller.
+
+ Example:
+
+ package MyAPP;
+ use strict;
+ use warnings;
+ use Log::Handler myapp => 'LOG';
+
+ LOG->config(config => 'myapp.conf');
+ LOG->info('hello world');
+
+ Now you can access the logger after you import it.
+
+ package MyAPP::Foo;
+ use Log::Handler myapp => 'LOG';
+
+ LOG->info('message');
+
+ If you want to import another accessor name ...
+
+ package MyAPP::Bar;
+ use Log::Handler myapp => 'MYLOG';
+
+ MYLOG->info('message');
+
+ Another way to get the logger is to call "get_logger()" if you don't
+ want to create an accessor.
+
+ package MyAPP::Foo::Bar;
+ use Log::Handler;
+
+ my $log = Log::Handler->get_logger('myapp');
+ $log->info('message');
+
+ For a little example you can take a look into the examples directory of
+ the distribution (Log-Handler-$VERSION/examples/logger.pl).
+
EXAMPLES
Log::Handler::Examples
@@ -724,7 +827,6 @@
PREREQUISITES
Prerequisites for all modules:
- Perl 5.6.1
Carp
Data::Dumper
Devel::Backtrace
Modified: trunk/liblog-handler-perl/debian/changelog
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/liblog-handler-perl/debian/changelog?rev=27505&op=diff
==============================================================================
--- trunk/liblog-handler-perl/debian/changelog (original)
+++ trunk/liblog-handler-perl/debian/changelog Sun Nov 30 17:03:14 2008
@@ -1,3 +1,10 @@
+liblog-handler-perl (0.50-1) UNRELEASED; urgency=low
+
+ * New upstream release.
+ * Add myself to Uploaders.
+
+ -- Ansgar Burchardt <ansgar at 43-1.org> Sun, 30 Nov 2008 17:52:14 +0100
+
liblog-handler-perl (0.49-1) unstable; urgency=low
[ gregor herrmann ]
Modified: trunk/liblog-handler-perl/debian/control
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/liblog-handler-perl/debian/control?rev=27505&op=diff
==============================================================================
--- trunk/liblog-handler-perl/debian/control (original)
+++ trunk/liblog-handler-perl/debian/control Sun Nov 30 17:03:14 2008
@@ -7,7 +7,8 @@
libuniversal-require-perl, libdbi-perl, libemail-date-perl
Maintainer: Debian Perl Group <pkg-perl-maintainers at lists.alioth.debian.org>
Uploaders: Roberto C. Sanchez <roberto at connexer.com>,
- gregor herrmann <gregoa at debian.org>, Rene Mayorga <rmayorga at debian.org.sv>
+ gregor herrmann <gregoa at debian.org>, Rene Mayorga <rmayorga at debian.org.sv>,
+ Ansgar Burchardt <ansgar at 43-1.org>
Standards-Version: 3.8.0
Homepage: http://search.cpan.org/dist/Log-Handler/
Vcs-Svn: svn://svn.debian.org/pkg-perl/trunk/liblog-handler-perl/
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=27505&op=diff
==============================================================================
--- trunk/liblog-handler-perl/lib/Log/Handler.pm (original)
+++ trunk/liblog-handler-perl/lib/Log/Handler.pm Sun Nov 30 17:03:14 2008
@@ -16,7 +16,27 @@
newline => 1,
});
- $log->warning("a warinng here");
+ $log->warning("warn message");
+
+Or
+
+ # init myapp logger with accessor LOG
+ package MyApp;
+ use Log::Handler myapp => 'LOG';
+
+ LOG->add(screen => { maxlevel => 'info' });
+ LOG->info("info message");
+
+ # import myapp logger with accessor LOG
+ package MyApp::Foo;
+ use Log::Handler myapp => 'LOG';
+ LOG->info("info message from MyApp::Foo");
+
+ # get myapp logger with get_logger()
+ package MyApp::Bar;
+ use Log::Handler;
+ my $log = Log::Handler->get_logger('myapp');
+ $log->info("info message from MyApp::Bar");
=head1 DESCRIPTION
@@ -351,9 +371,9 @@
$log->add(screen => {
maxlevel => 'info',
newline => 1,
- filter_caller => qr/^Foo::Bar$/,
+ filter_caller => qr/^Foo::Bar\z/,
# or
- # filter_caller => '^Foo::Bar$',
+ # filter_caller => '^Foo::Bar\z',
});
package Foo::Bar;
@@ -365,6 +385,14 @@
1;
This would only log the message from the package C<Foo::Bar>.
+
+=item B<except_caller>
+
+This options is just the opposite of C<filter_caller>.
+
+If you want to log messages from all callers but C<Foo::Bar>:
+
+ except_caller => qr/^Foo::Bar\z/
=item B<alias>
@@ -750,6 +778,85 @@
Note: valid character for the key name are: C<[%\w\-\.]+>
+=head2 create_logger()
+
+C<create_logger()> is the same like C<new()> but it creates a global
+logger.
+
+ my $log = Log::Handler->create_logger('myapp');
+
+If you want to create more than one object you can call
+
+ my @logger = Log::Handler->create_logger('myapp1', 'myapp2', ...);
+
+=head2 get_logger()
+
+With C<get_logger()> it's possible to get a logger that was created
+with C<create_logger()> or with
+
+ use Log::Handler 'myapp';
+
+Just call
+
+ my $log = Log::Handler->get_logger('myapp');
+
+Or
+
+ my @logger = Log::Handler->create_logger('myapp1', 'myapp2', ...);
+
+=head1 GLOBAL LOG HANDLER
+
+Since version C<0.50> it's possible to define a application logger.
+This means to create a C<Log::Handler> object and import it into
+all modules of your program.
+
+ use Log::Handler alias => accessor;
+
+The accessor is created into the namespace of the caller and
+referenced to the alias.
+
+If the alias doesn't exists then a new C<Log::Handler> object
+will be created.
+
+If no acesseor is set then no accessor is exported into the
+namespace of the caller.
+
+Example:
+
+ package MyAPP;
+ use strict;
+ use warnings;
+ use Log::Handler myapp => 'LOG';
+
+ LOG->config(config => 'myapp.conf');
+ LOG->info('hello world');
+
+Now you can access the logger after you import it.
+
+ package MyAPP::Foo;
+ use Log::Handler myapp => 'LOG';
+
+ LOG->info('message');
+
+If you want to import another accessor name ...
+
+ package MyAPP::Bar;
+ use Log::Handler myapp => 'MYLOG';
+
+ MYLOG->info('message');
+
+Another way to get the logger is to call C<get_logger()> if you
+don't want to create an accessor.
+
+ package MyAPP::Foo::Bar;
+ use Log::Handler;
+
+ my $log = Log::Handler->get_logger('myapp');
+ $log->info('message');
+
+For a little example you can take a look into the examples directory
+of the distribution (Log-Handler-$VERSION/examples/logger.pl).
+
=head1 EXAMPLES
L<Log::Handler::Examples>
@@ -762,7 +869,6 @@
Prerequisites for all modules:
- Perl 5.6.1
Carp
Data::Dumper
Devel::Backtrace
@@ -853,7 +959,7 @@
use Log::Handler::Pattern;
use base qw(Log::Handler::Levels);
-our $VERSION = '0.49';
+our $VERSION = '0.50';
our $ERRSTR = '';
# $TRACE and $CALLER_LEVEL are both used as global
@@ -865,6 +971,9 @@
# $CALLER_LEVEL is used to determine the current caller level
our $CALLER_LEVEL = 0;
our $TRACE = 0;
+
+# safe logger by app
+my %LOGGER;
# Some constants...
use constant PRIORITY => 10;
@@ -924,6 +1033,53 @@
socket => 'Log::Handler::Output::Socket',
);
+# use Log::Handler foo => 'LOGFOO', bar => 'LOGBAR';
+# use Log::Handler qw/foo LOGFOO bar LOGBAR/;
+sub import {
+ return unless @_ > 1;
+ my $class = shift;
+ my %create = @_ > 1 ? @_ : (@_, undef);
+ my $caller = (caller)[0];
+
+ while (my ($appl, $export) = each %create) {
+ my $logger = ();
+
+ if (!exists $LOGGER{$appl}) {
+ $LOGGER{$appl} = __PACKAGE__->new();
+ }
+
+ if ($export) {
+ no strict 'refs';
+ my $method = $caller.'::'.$export;
+ *{$method} = sub { $LOGGER{$appl} };
+ }
+ }
+}
+
+sub get_logger {
+ @_ > 1 || croak 'Usage: Log::Handler->get_logger($app)';
+ my $class = shift;
+
+ foreach my $logger (@_) {
+ if (!exists $LOGGER{$logger}) {
+ croak "logger '$logger' does not exists";
+ }
+ }
+
+ return @LOGGER{@_};
+}
+
+sub create_logger {
+ @_ > 1 || croak 'Usage: Log::Handler->create_logger($app)';
+ my $class = shift;
+
+ foreach my $logger (@_) {
+ $LOGGER{$logger} = __PACKAGE__->new();
+ }
+
+ return @LOGGER{@_};
+}
+
sub new {
my $class = shift;
@@ -1098,8 +1254,9 @@
debug_trace
die_on_errors
filter
+ filter_message
filter_caller
- filter_message
+ except_caller
maxlevel
message_layout
message_pattern
@@ -1248,6 +1405,10 @@
type => Params::Validate::SCALAR | Params::Validate::SCALARREF,
optional => 1,
},
+ except_caller => {
+ type => Params::Validate::SCALAR | Params::Validate::SCALARREF,
+ optional => 1,
+ },
});
if ($options{filter_message}) {
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=27505&op=diff
==============================================================================
--- trunk/liblog-handler-perl/lib/Log/Handler/Examples.pod (original)
+++ trunk/liblog-handler-perl/lib/Log/Handler/Examples.pod Sun Nov 30 17:03:14 2008
@@ -1,6 +1,61 @@
=head1 NAME
Log::Handler::Examples - Examples.
+
+=head1 CREATE LOGGER
+
+Quite simple
+
+ use Log::Handler;
+
+ my $log = Log::Handler->new();
+ $log->add( screen => \%options );
+
+Create a application logger and accessor LOG
+
+ use Log::Handler myapp => 'LOG';
+
+ LOG->add( screen => \%options );
+
+Create a application logger without accessor
+
+ use Log::Handler 'myapp';
+
+ my $log = Log::Handler->get_logger('myapp');
+ $log->add( screen => \%options );
+
+Create application logger with C<create_logger()>
+
+ use Log::Handler;
+
+ my $log = Log::Handler->create_logger('myapp');
+ $log->add( screen => \%options );
+
+Another self-explanatory examples
+
+ use Log::Handler l1 => 'LOG1', l2 => 'LOG2', l3 => 'LOG3';
+
+ @logger = Log::Handler->create_logger(qw/l1 l2 l3/);
+
+ @logger = Log::Handler->get_logger(qw/l1 l2 l3/);
+
+Once created you can import a application logger into all
+modules of your project:
+
+ package MyApp;
+ use Log::Handler myapp => 'LOG';
+ LOG->add( screen => \%options );
+
+ package MyApp::Foo;
+ # Import it with an accessor
+ use Log::Handler myapp => 'LOG';
+ LOG->info('message');
+
+ package MyApp::Bar;
+ use Log::Handler;
+ # Import it with get_logger()
+ my $log = Log::Handler->get_logger('myapp');
+ $log->info('message');
=head1 ADD OUTPUTS
@@ -432,41 +487,6 @@
This would dump the hash only if the level debug is active.
-=head1 GLOBAL LOG HANDLER
-
-A long time I was thinking about to provide a global log mechanism like
-
- # use Log::Handler alias => accessor;
- use Log::Handler myapp => 'LOG';
- LOG->config(config => 'myapp.conf');
-
-and then just inlucde C<Log::Handler> into all other modules of your project and
-use a global logger like:
-
- use Log::Handler 'myapp';
- LOG->info('an info here');
-
-I through away this idea because it would come with a lot of problems.
-
-If you want to use a feature like this then you can write your own thing.
-
- package MyAPP::Logger;
- use strict;
- use warnings;
- use Log::Handler;
- use constant LOG => Log::Handler->new();
- require Exporter;
- our @ISA = qw(Exporter);
- our @EXPORT = qw(LOG);
- LOG->config(config => 'myapp.conf');
- 1;
-
-Now you can include C<MyAPP::Logger> into all the modules of your project and access
-the logger with
-
- use MyAPP::Logger;
- LOG->info('an info here');
-
=head1 AUTHOR
Jonny Schulz <jschulz.cpan(at)bloonix.de>.
Modified: trunk/liblog-handler-perl/lib/Log/Handler/Output.pm
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/liblog-handler-perl/lib/Log/Handler/Output.pm?rev=27505&op=diff
==============================================================================
--- trunk/liblog-handler-perl/lib/Log/Handler/Output.pm (original)
+++ trunk/liblog-handler-perl/lib/Log/Handler/Output.pm Sun Nov 30 17:03:14 2008
@@ -58,12 +58,15 @@
my $level = shift;
my $wanted = {message=>join(' ', grep defined, @_)};
my $output = $self->{output};
- my $pattern = $self->{pattern};
my $message = { };
+ my $caller = ();
if ($self->{filter_caller}) {
- my $caller = (caller(1+$Log::Handler::CALLER_LEVEL))[0];
+ $caller = (caller(1+$Log::Handler::CALLER_LEVEL))[0];
return 1 if $caller !~ $self->{filter_caller};
+ } elsif ($self->{except_caller}) {
+ $caller = (caller(1+$Log::Handler::CALLER_LEVEL))[0];
+ return 1 if $caller =~ $self->{except_caller};
}
# The patterns must be generated for each output. The reason
More information about the Pkg-perl-cvs-commits
mailing list