[Koha-bugs] [Bug 8190] Add a logging module to Koha

bugzilla-daemon at bugs.koha-community.org bugzilla-daemon at bugs.koha-community.org
Wed Jun 12 21:38:36 CEST 2013


http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=8190

--- Comment #108 from Chris Cormack <chris at bigballofwax.co.nz> ---
(In reply to comment #107)
> (In reply to comment #106)
> > That begs a question, though -- what do we need in Koha?
> > 
> > One part of the answer to that question, for me, and I suspect for most
> > folks who administer more than one Koha database or who administer services
> > in addition to Koha, is syslog support.  Log::LogLite doesn't provide such
> > support, whereas Log4Perl does in addition to supporting appending to
> > traditional log files.
> > 
> > Also, Chris in comment 58 all but proposed a counter-patch.  Would the
> > original patch submitter respond to that comment, please?
> 
> This development was written 1 year ago for BibLibre branches. We need a
> logger with different levels (like many softwares).
> I provided a simple module which does what we want.
> Since this is a simple class, it could be rewritten easily by someone having
> a better idea.
> The patch proposed by Chris was not working but it could be the second step
> to this development.

The point of my counter proposal was that we do not need another module, we can
add some lines to context.pm using Log4perl and not have another module to
maintain ourselves.

Pushing this now as it is, would mean we would just have to remove it again if
we wanted to do it the Log4perl way. IE if people think that is a good idea,
then I can write a working patch for that, however if this is pushed, I won't. 
I also won't be happy that we have yet another module we have to maintain
instead.

I maintain we dont need a new logging module, we just need to add logging to
C4::Context.

I don't like suggesting people abandon the work they have done, but I have real
reservations about adding yet another module we have to maintain. The fact that
it is a class doesn't really affect this point at all
My point was you don't need another module, we can simply do 

use Log::Log4perl qw(:levels get_logger);

my $layout_class   = "Log::Log4perl::Layout::PatternLayout";
my $layout_pattern = "[%d] %p - %M - %m - %T%n";

my $config = <<"END";
      log4perl.logger = INFO, Logfile, Screen

      log4perl.appender.Logfile = Log::Log4perl::Appender::File
      log4perl.appender.Logfile.filename = $ENV{KOHA_LOG}
      log4perl.appender.Logfile.mode=append
      log4perl.appender.Logfile.layout = $layout_class
      log4perl.appender.Logfile.layout.ConversionPattern=$layout_pattern
      log4perl.appender.Screen  = Log::Log4perl::Appender::Screen
      log4perl.appender.Screen.layout = $layout_class
      log4perl.appender.Screen.layout.ConversionPattern = $layout_pattern
END

Log::Log4perl->init( \$config );

and then in there a sub

sub logger
{
    my $self = shift;

    if ( defined( $context->{"logger"} ) ) {
        return $context->{"logger"};
    }

    $context->{"logger"} = Log::Log4perl->get_logger('C4::Context');
    $context->{"logger"}->level(C4::Context->preference("LogLevel"));

    return $context->{"logger"};
}

(Or something very similar in C4::Context)

Then anywhere we want to log C4::Context->logger() gives us a logger

-- 
You are receiving this mail because:
You are watching all bug changes.


More information about the Koha-bugs mailing list