Bug 14167: (QA followup) Adjust category handling in Koha::Logger
authorMarcel de Rooy <m.de.rooy@rijksmuseum.nl>
Fri, 5 Jun 2015 08:08:22 +0000 (10:08 +0200)
committerTomas Cohen Arazi <tomascohen@unc.edu.ar>
Tue, 21 Jul 2015 13:17:49 +0000 (10:17 -0300)
The first patch makes the category parameter mandatory.
This patch makes it optional, falling back to the current package. This is
the expected log4perl model. It would not be necessary to pass the class
name everywhere (check subclasses..)
It also adds a delimiter between the interface and the class name.

This allows you to add config lines like:

log4perl.logger.opac.C4.Auth = DEBUG, OPAC
log4perl.logger.intranet.C4.Circulation = TRACE, INTRANET

The first line would make the logger more sensitive to C4::Auth log
messages while staying at the WARN level for other messages, etc. The
second line makes the trace visible from the renewal example.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Tomas Cohen Arazi <tomascohen@unc.edu.ar>
Koha/Logger.pm

index 2fcbb6f..6ba0af8 100644 (file)
@@ -54,14 +54,20 @@ BEGIN {
     Log::Log4perl->init_once($conf);
 }
 
-sub get {
-    my ( $class, $category, $interface ) = @_;
+=head2 get
 
-    croak("No category passed in!") unless $category;
+    Returns a log4perl object.
+    Category and interface parameter are optional.
+    Normally, the category should follow the current package and the interface
+    should be set correctly via C4::Context.
 
-    $interface ||= C4::Context->interface();
+=cut
 
-    return Log::Log4perl->get_logger("$interface.$category");
+sub get {
+    my ( $class, $category, $interface ) = @_;
+    $interface ||= C4::Context->interface();
+    $category = caller if !$category;
+    return Log::Log4perl->get_logger( $interface. '.'. $category );
 }
 
 =head1 AUTHOR