[liblog-handler-perl] 01/01: Imported Upstream version 0.79

Salvatore Bonaccorso carnil at debian.org
Wed Sep 18 06:15:15 UTC 2013


This is an automated email from the git hooks/post-receive script.

carnil pushed a commit to annotated tag upstream/0.79
in repository liblog-handler-perl.

commit b96312f923e2a146ad6751686ed182f79642de0b
Author: Salvatore Bonaccorso <carnil at debian.org>
Date:   Wed Sep 18 07:38:25 2013 +0200

    Imported Upstream version 0.79
---
 ChangeLog                     |    3 ++
 MANIFEST                      |    2 +
 META.json                     |  115 +++++++++++++++++++++++++++++++++++++++++
 META.yml                      |   10 ++--
 Makefile.PL                   |   38 +++++++-------
 README                        |   45 ++++++++++++++++
 examples/category/category.pl |   24 +++++++++
 lib/Log/Handler.pm            |   59 ++++++++++++++++++++-
 lib/Log/Handler/Levels.pm     |   17 +++++-
 lib/Log/Handler/Output.pm     |   15 ++----
 10 files changed, 291 insertions(+), 37 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 369c0e3..9807e90 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,6 @@
+0.79    Released at 2013-09-06.
+        - Added option "category".
+
 0.78    Released at 2013-05-16.
         - Fixed bug in validate->reload for default configs (RT #85346).
 
diff --git a/MANIFEST b/MANIFEST
index 2695cd4..997ff81 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -1,6 +1,7 @@
 Build.PL
 ChangeLog
 examples/benchmark/benchmark.pl
+examples/category/category.pl
 examples/config/example.conf
 examples/config/example.pl
 examples/config/example.props
@@ -40,6 +41,7 @@ lib/Log/Handler/Plugin/YAML.pm
 LICENCE
 Makefile.PL
 MANIFEST			This list of files
+META.json
 META.yml
 README
 t/000-use.t
diff --git a/META.json b/META.json
new file mode 100644
index 0000000..8f14104
--- /dev/null
+++ b/META.json
@@ -0,0 +1,115 @@
+{
+   "abstract" : "Log messages to several outputs.",
+   "author" : [
+      "Jonny Schulz"
+   ],
+   "dynamic_config" : 1,
+   "generated_by" : "Module::Build version 0.4001, CPAN::Meta::Converter version 2.110440",
+   "license" : [
+      "perl_5"
+   ],
+   "meta-spec" : {
+      "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
+      "version" : "2"
+   },
+   "name" : "Log-Handler",
+   "prereqs" : {
+      "configure" : {
+         "requires" : {
+            "Module::Build" : "0.40"
+         }
+      },
+      "runtime" : {
+         "recommends" : {
+            "Config::General" : 0,
+            "Config::Properties" : 0,
+            "DBI" : 0,
+            "Email::Date" : 0,
+            "IO::Socket" : 0,
+            "Net::SMTP" : 0,
+            "YAML" : 0
+         },
+         "requires" : {
+            "Carp" : 0,
+            "Data::Dumper" : 0,
+            "Fcntl" : 0,
+            "File::Spec" : 0,
+            "POSIX" : 0,
+            "Params::Validate" : 0,
+            "Sys::Hostname" : 0,
+            "Test::More" : 0,
+            "Time::HiRes" : 0,
+            "UNIVERSAL" : 0
+         }
+      }
+   },
+   "provides" : {
+      "Log::Handler" : {
+         "file" : "lib/Log/Handler.pm",
+         "version" : "0.79"
+      },
+      "Log::Handler::Config" : {
+         "file" : "lib/Log/Handler/Config.pm",
+         "version" : "0.08"
+      },
+      "Log::Handler::Levels" : {
+         "file" : "lib/Log/Handler/Levels.pm",
+         "version" : "0.06"
+      },
+      "Log::Handler::Output" : {
+         "file" : "lib/Log/Handler/Output.pm",
+         "version" : "0.09"
+      },
+      "Log::Handler::Output::DBI" : {
+         "file" : "lib/Log/Handler/Output/DBI.pm",
+         "version" : "0.12"
+      },
+      "Log::Handler::Output::Email" : {
+         "file" : "lib/Log/Handler/Output/Email.pm",
+         "version" : "0.08"
+      },
+      "Log::Handler::Output::File" : {
+         "file" : "lib/Log/Handler/Output/File.pm",
+         "version" : "0.06"
+      },
+      "Log::Handler::Output::Forward" : {
+         "file" : "lib/Log/Handler/Output/Forward.pm",
+         "version" : "0.03"
+      },
+      "Log::Handler::Output::Screen" : {
+         "file" : "lib/Log/Handler/Output/Screen.pm",
+         "version" : "0.06"
+      },
+      "Log::Handler::Output::Sendmail" : {
+         "file" : "lib/Log/Handler/Output/Sendmail.pm",
+         "version" : "0.06"
+      },
+      "Log::Handler::Output::Socket" : {
+         "file" : "lib/Log/Handler/Output/Socket.pm",
+         "version" : "0.08"
+      },
+      "Log::Handler::Pattern" : {
+         "file" : "lib/Log/Handler/Pattern.pm",
+         "version" : "0.07"
+      },
+      "Log::Handler::Plugin::Config::General" : {
+         "file" : "lib/Log/Handler/Plugin/Config/General.pm",
+         "version" : "0.02"
+      },
+      "Log::Handler::Plugin::Config::Properties" : {
+         "file" : "lib/Log/Handler/Plugin/Config/Properties.pm",
+         "version" : "0.03"
+      },
+      "Log::Handler::Plugin::YAML" : {
+         "file" : "lib/Log/Handler/Plugin/YAML.pm",
+         "version" : "0.03"
+      }
+   },
+   "release_status" : "stable",
+   "resources" : {
+      "license" : [
+         "http://dev.perl.org/licenses/"
+      ]
+   },
+   "version" : "0.79"
+}
diff --git a/META.yml b/META.yml
index 2c30e66..e1b422a 100644
--- a/META.yml
+++ b/META.yml
@@ -2,9 +2,11 @@
 abstract: 'Log messages to several outputs.'
 author:
   - 'Jonny Schulz'
+build_requires: {}
 configure_requires:
-  Module::Build: 0.36
-generated_by: 'Module::Build version 0.3607'
+  Module::Build: 0.40
+dynamic_config: 1
+generated_by: 'Module::Build version 0.4001, CPAN::Meta::Converter version 2.110440'
 license: perl
 meta-spec:
   url: http://module-build.sourceforge.net/META-spec-v1.4.html
@@ -13,7 +15,7 @@ name: Log-Handler
 provides:
   Log::Handler:
     file: lib/Log/Handler.pm
-    version: 0.78
+    version: 0.79
   Log::Handler::Config:
     file: lib/Log/Handler/Config.pm
     version: 0.08
@@ -77,4 +79,4 @@ requires:
   UNIVERSAL: 0
 resources:
   license: http://dev.perl.org/licenses/
-version: 0.78
+version: 0.79
diff --git a/Makefile.PL b/Makefile.PL
index 9fceebb..14c6869 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -1,23 +1,23 @@
-# Note: this file was auto-generated by Module::Build::Compat version 0.3607
+# Note: this file was auto-generated by Module::Build::Compat version 0.4001
 use ExtUtils::MakeMaker;
 WriteMakefile
 (
-          'PL_FILES' => {},
-          'INSTALLDIRS' => 'site',
-          'NAME' => 'Log::Handler',
-          'EXE_FILES' => [],
-          'VERSION_FROM' => 'lib/Log/Handler.pm',
-          'PREREQ_PM' => {
-                           'UNIVERSAL' => 0,
-                           'File::Spec' => 0,
-                           'Fcntl' => 0,
-                           'Data::Dumper' => 0,
-                           'Time::HiRes' => 0,
-                           'Carp' => 0,
-                           'Test::More' => 0,
-                           'Params::Validate' => 0,
-                           'POSIX' => 0,
-                           'Sys::Hostname' => 0
-                         }
-        )
+  'PL_FILES' => {},
+  'INSTALLDIRS' => 'site',
+  'NAME' => 'Log::Handler',
+  'EXE_FILES' => [],
+  'VERSION_FROM' => 'lib/Log/Handler.pm',
+  'PREREQ_PM' => {
+                   'UNIVERSAL' => 0,
+                   'File::Spec' => 0,
+                   'Fcntl' => 0,
+                   'Data::Dumper' => 0,
+                   'Time::HiRes' => 0,
+                   'Carp' => 0,
+                   'Test::More' => 0,
+                   'Params::Validate' => 0,
+                   'POSIX' => 0,
+                   'Sys::Hostname' => 0
+                 }
+)
 ;
diff --git a/README b/README
index 4e74452..64c1541 100644
--- a/README
+++ b/README
@@ -530,6 +530,51 @@ METHODS
 
         would cause an error!
 
+    category
+        The parameter `category' works like `filter_caller' but is much
+        easier to configure. You can set a comma separated list of modules.
+        As example if you would set the category to
+
+            category => "MyApp::User"
+
+        then all messages of MyApp::User and the submodules would be logged.
+
+        Example:
+
+            my $log = Log::Handler->new();
+
+            $log->add(
+                screen => {
+                    maxlevel => "info",
+                    category => "MyApp::User, MyApp::Session"
+                }
+            );
+
+            package MyApp;
+            $log->info(__PACKAGE__);
+
+            package MyApp::Products;
+            $log->info(__PACKAGE__);
+
+            package MyApp::User;
+            $log->info(__PACKAGE__);
+
+            package MyApp::Users;
+            $log->info(__PACKAGE__);
+
+            package MyApp::User::Settings;
+            $log->info(__PACKAGE__);
+
+            package MyApp::Session;
+            $log->info(__PACKAGE__);
+
+            package MyApp::Session::Settings;
+            $log->info(__PACKAGE__);
+
+        The messages of `MyApp' and `MyApp::Products' would not be logged.
+
+        The usage of categories is much faster than to filter by caller.
+
     filter_caller
         You can use this option to set a package name. Only messages from
         this packages will be logged.
diff --git a/examples/category/category.pl b/examples/category/category.pl
new file mode 100644
index 0000000..0e034f0
--- /dev/null
+++ b/examples/category/category.pl
@@ -0,0 +1,24 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+use Log::Handler;
+
+my $log = Log::Handler->new();
+
+$log->add(
+    screen => {
+        maxlevel => "info",
+        category => "Foo"
+    }
+);
+
+$log->info("Hello World!");
+
+package Foo;
+$log->info(__PACKAGE__);
+
+package Foo::Bar;
+$log->info(__PACKAGE__);
+
+package Foooo;
+$log->info(__PACKAGE__);
diff --git a/lib/Log/Handler.pm b/lib/Log/Handler.pm
index 69d3ecf..9caab09 100644
--- a/lib/Log/Handler.pm
+++ b/lib/Log/Handler.pm
@@ -572,6 +572,51 @@ NOTE that re-eval in regexes is not valid! Something like
 
 would cause an error!
 
+=item B<category>
+
+The parameter C<category> works like C<filter_caller> but is much easier to configure.
+You can set a comma separated list of modules. As example if you would set the category to
+
+    category => "MyApp::User"
+
+then all messages of MyApp::User and the submodules would be logged.
+
+Example:
+
+    my $log = Log::Handler->new();
+
+    $log->add(
+        screen => {
+            maxlevel => "info",
+            category => "MyApp::User, MyApp::Session"
+        }
+    );
+
+    package MyApp;
+    $log->info(__PACKAGE__);
+
+    package MyApp::Products;
+    $log->info(__PACKAGE__);
+
+    package MyApp::User;
+    $log->info(__PACKAGE__);
+
+    package MyApp::Users;
+    $log->info(__PACKAGE__);
+
+    package MyApp::User::Settings;
+    $log->info(__PACKAGE__);
+
+    package MyApp::Session;
+    $log->info(__PACKAGE__);
+
+    package MyApp::Session::Settings;
+    $log->info(__PACKAGE__);
+
+The messages of C<MyApp> and C<MyApp::Products> would not be logged.
+
+The usage of categories is much faster than to filter by caller.
+
 =item B<filter_caller>
 
 You can use this option to set a package name. Only messages from this
@@ -1059,7 +1104,7 @@ use Log::Handler::Pattern;
 use UNIVERSAL;
 use base qw(Log::Handler::Levels);
 
-our $VERSION = "0.78";
+our $VERSION = "0.79";
 our $ERRSTR  = "";
 
 # $TRACE and $CALLER_LEVEL are both used as global
@@ -1579,6 +1624,7 @@ sub _split_options {
         timeformat
         dateformat
         remove_on_reload
+        category
     );
 
     foreach my $key (keys %$opts) {
@@ -1725,6 +1771,10 @@ sub _validate_options {
             type => Params::Validate::SCALAR | Params::Validate::SCALARREF,
             optional => 1,
         },
+        category => {
+            type => Params::Validate::SCALAR,
+            optional => 1,
+        },
         except_caller => {
             type => Params::Validate::SCALAR | Params::Validate::SCALARREF,
             optional => 1,
@@ -1735,6 +1785,13 @@ sub _validate_options {
         },
     });
 
+    if ($options{category}) {
+        my $category = $options{category};
+        $category =~ s/\s//g;
+        $category = "^(?:" . join("|", map { $_ } split(/,/, $category) ) . ")(?:::|\\z)";
+        $options{category} = qr/$category/;
+    }
+
     if (!$options{alias}) {
         for (;;) {
             my $rand = rand();
diff --git a/lib/Log/Handler/Levels.pm b/lib/Log/Handler/Levels.pm
index 2825c27..614f87d 100644
--- a/lib/Log/Handler/Levels.pm
+++ b/lib/Log/Handler/Levels.pm
@@ -202,13 +202,28 @@ foreach my $routine (keys %LEVELS_BY_ROUTINE) {
             use strict 'refs';
             my $self   = shift;
             my $levels = $self->{levels};
-            my $errors = ();
+            my ($errors, $caller);
 
             if ( !$levels->{$level} ) {
                 return 1;
             }
 
             foreach my $output ( @{$levels->{$level}} ) {
+                if ($output->{category} || $output->{filter_caller} || $output->{except_caller}) {
+                    if (!$caller) {
+                        $caller = (caller($Log::Handler::CALLER_LEVEL))[0];
+                    }
+
+                    if ($output->{category}) {
+                        my $category = $output->{category};
+                        return 1 if $caller !~ $output->{category};
+                    } elsif ($output->{filter_caller}) {
+                        return 1 if $caller !~ $output->{filter_caller};
+                    } elsif ($output->{except_caller}) {
+                        return 1 if $caller =~ $output->{except_caller};
+                    }
+                }
+
                 if ( !$output->log($level, @_) ) {
                     if ( defined $errors ) {
                         $errors .= '; ' . $output->errstr;
diff --git a/lib/Log/Handler/Output.pm b/lib/Log/Handler/Output.pm
index eb13fd0..0b2d864 100644
--- a/lib/Log/Handler/Output.pm
+++ b/lib/Log/Handler/Output.pm
@@ -54,20 +54,11 @@ sub new {
 }
 
 sub log {
-    my $self  = shift;
+    my $self = shift;
     my $level = shift;
-
-    if ($self->{filter_caller}) {
-        my $caller = (caller(1+$Log::Handler::CALLER_LEVEL))[0];
-        return 1 if $caller !~ $self->{filter_caller};
-    } elsif ($self->{except_caller}) {
-        my $caller = (caller(1+$Log::Handler::CALLER_LEVEL))[0];
-        return 1 if $caller =~ $self->{except_caller};
-    }
-
-    my $output  = $self->{output};
+    my $output = $self->{output};
     my $message = { };
-    my $wanted  = { message => join(" ", grep defined, @_) };
+    my $wanted = { message => join(" ", grep defined, @_) };
 
     # The patterns must be generated for each output. The reason
     # is that each output can have their own time/date format

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/liblog-handler-perl.git



More information about the Pkg-perl-cvs-commits mailing list