Bugzilla – Attachment 40664 Details for
Bug 14167
Add Koha::Logger based on Log4perl
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 14167 [QA Followup] - Tidy Koha/Logger.pm
Bug-14167-QA-Followup---Tidy-KohaLoggerpm.patch (text/plain), 5.59 KB, created by
Kyle M Hall (khall)
on 2015-06-26 13:59:54 UTC
(
hide
)
Description:
Bug 14167 [QA Followup] - Tidy Koha/Logger.pm
Filename:
MIME Type:
Creator:
Kyle M Hall (khall)
Created:
2015-06-26 13:59:54 UTC
Size:
5.59 KB
patch
obsolete
>From 8e45196e4910c7fc2dcfee339b9d5374ec9f7c9c Mon Sep 17 00:00:00 2001 >From: Kyle M Hall <kyle@bywatersolutions.com> >Date: Thu, 25 Jun 2015 14:23:48 -0400 >Subject: [PATCH] Bug 14167 [QA Followup] - Tidy Koha/Logger.pm > >--- > Koha/Logger.pm | 83 +++++++++++++++++++++++++++++++------------------------- > 1 files changed, 46 insertions(+), 37 deletions(-) > >diff --git a/Koha/Logger.pm b/Koha/Logger.pm >index 7947657..1024cc7 100644 >--- a/Koha/Logger.pm >+++ b/Koha/Logger.pm >@@ -52,17 +52,16 @@ BEGIN { > > sub get { > my ( $class, $params ) = @_; >- my $interface = $params? ($params->{interface} || C4::Context->interface): >- C4::Context->interface; >- my $category = $params? ($params->{category} || caller): caller; >- my $l4pcat= $interface. '.'. $category; >+ my $interface = $params ? ( $params->{interface} || C4::Context->interface ) : C4::Context->interface; >+ my $category = $params ? ( $params->{category} || caller ) : caller; >+ my $l4pcat = $interface . '.' . $category; > >- my $init= _init(); >+ my $init = _init(); > my $self = {}; >- if( $init ) { >- $self->{logger} = Log::Log4perl->get_logger( $l4pcat ); >- $self->{cat} = $l4pcat; >- $self->{logs} = $init if ref $init; >+ if ($init) { >+ $self->{logger} = Log::Log4perl->get_logger($l4pcat); >+ $self->{cat} = $l4pcat; >+ $self->{logs} = $init if ref $init; > } > bless $self, $class; > return $self; >@@ -80,18 +79,22 @@ sub get { > > sub AUTOLOAD { > my ( $self, $line ) = @_; >- my $method= $Koha::Logger::AUTOLOAD; >+ my $method = $Koha::Logger::AUTOLOAD; > $method =~ s/^Koha::Logger:://; > >- if( !exists $self->{logger} ) { >+ if ( !exists $self->{logger} ) { >+ > #do not use log4perl; no print to stderr >- } elsif( !$self->_recheck_logfile ) { >+ } >+ elsif ( !$self->_recheck_logfile ) { > print STDERR "Log file not writable for log4perl\n"; > print STDERR "$method: $line\n" if $line; >- } elsif( $self->{logger}->can($method) ) { #use log4perl >- $self->{logger}->$method( $line ); >+ } >+ elsif ( $self->{logger}->can($method) ) { #use log4perl >+ $self->{logger}->$method($line); > return 1; >- } else { # we should not really get here >+ } >+ else { # we should not really get here > print STDERR "ERROR: Unsupported method $method\n"; > } > return; >@@ -103,7 +106,7 @@ sub AUTOLOAD { > > =cut > >-sub DESTROY {} >+sub DESTROY { } > > =head2 _init, _check_conf and _recheck_logfile > >@@ -112,56 +115,62 @@ sub DESTROY {} > sub _init { > my $rv; > if ( exists $ENV{"LOG4PERL_CONF"} and $ENV{'LOG4PERL_CONF'} and -s $ENV{"LOG4PERL_CONF"} ) { >+ > # Check for web server level configuration first > # In this case we ASSUME that you correctly arranged logfile > # permissions. If not, log4perl will crash on you. > # We will not parse apache files here. > Log::Log4perl->init_once( $ENV{"LOG4PERL_CONF"} ); >- } elsif ( C4::Context->config("log4perl_conf") ) { >+ } >+ elsif ( C4::Context->config("log4perl_conf") ) { >+ > # Now look in the koha conf file. We only check the permissions of > # the default logfiles. For the rest, we again ASSUME that > # you arranged file permissions. >- my $conf= C4::Context->config("log4perl_conf"); >- if( $rv = _check_conf($conf) ) { >- Log::Log4perl->init_once( $conf ); >+ my $conf = C4::Context->config("log4perl_conf"); >+ if ( $rv = _check_conf($conf) ) { >+ Log::Log4perl->init_once($conf); > return $rv; >- } else { >+ } >+ else { > return 0; > } >- } else { >- # This means that you do not use log4perl currently. >- # We will not be forcing it. >- return 0; > } >- return 1; # if we make it here, log4perl did not crash :) >+ else { >+ # This means that you do not use log4perl currently. >+ # We will not be forcing it. >+ return 0; >+ } >+ return 1; # if we make it here, log4perl did not crash :) > } > >-sub _check_conf { # check logfiles in log4perl config (at initialization) >+sub _check_conf { # check logfiles in log4perl config (at initialization) > my $file = shift; > return if !-r $file; > open my $fh, '<', $file; > my @lines = <$fh>; > close $fh; > my @logs; >- foreach my $l ( @lines ) { >- if( $l =~ /(OPAC|INTRANET)\.filename\s*=\s*(.*)\s*$/i ) { >- # we only check the two default logfiles, skipping additional ones >+ foreach my $l (@lines) { >+ if ( $l =~ /(OPAC|INTRANET)\.filename\s*=\s*(.*)\s*$/i ) { >+ >+ # we only check the two default logfiles, skipping additional ones > return if !-w $2; >- push @logs, $1.':'.$2; >+ push @logs, $1 . ':' . $2; > } > } >- return if !@logs; # we should find one >+ return if !@logs; # we should find one > return \@logs; > } > >-sub _recheck_logfile { # recheck saved logfile when logging message >+sub _recheck_logfile { # recheck saved logfile when logging message > my $self = shift; > >- return 1 if !exists $self->{logs}; # remember? your own responsibility >- my $opac= $self->{cat}=~ /^OPAC/; >+ return 1 if !exists $self->{logs}; # remember? your own responsibility >+ my $opac = $self->{cat} =~ /^OPAC/; > my $log; >- foreach( @{$self->{logs}} ) { >- $log=$_ if $opac && /^OPAC:/ || !$opac && /^INTRANET:/; >+ foreach ( @{ $self->{logs} } ) { >+ $log = $_ if $opac && /^OPAC:/ || !$opac && /^INTRANET:/; > last if $log; > } > $log =~ s/^(OPAC|INTRANET)://; >-- >1.7.2.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 14167
:
38953
|
38954
|
38980
|
38981
|
38993
|
39103
|
39180
|
39886
|
39887
|
39888
|
39889
|
39890
|
39891
|
39892
|
39893
|
39894
|
39895
|
40200
|
40652
|
40653
|
40657
|
40658
|
40659
|
40660
|
40661
|
40662
|
40663
| 40664 |
41109
|
41111
|
41145
|
41146