From 2659f6415a38405758c068b1f1f68ab6acf6e466 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Fri, 5 Jun 2015 10:08:22 +0200 Subject: [PATCH] Bug 14167: [QA Follow-up] Adjust category handling in Koha::Logger Content-Type: text/plain; charset=utf-8 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 --- Koha/Logger.pm | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/Koha/Logger.pm b/Koha/Logger.pm index 2fcbb6f..6ba0af8 100644 --- a/Koha/Logger.pm +++ b/Koha/Logger.pm @@ -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 -- 1.7.10.4