View | Details | Raw Unified | Return to bug 25172
Collapse All | Expand All

(-)a/Koha/Logger.pm (-49 / +13 lines)
Lines 112-170 sub AUTOLOAD { Link Here
112
112
113
sub DESTROY { }
113
sub DESTROY { }
114
114
115
=head2 _init, _check_conf and _recheck_logfile
115
=head2 _init, _recheck_logfile
116
116
117
=cut
117
=cut
118
118
119
sub _init {
119
sub _init {
120
    my $rv;
121
    if ( exists $ENV{"LOG4PERL_CONF"} and $ENV{'LOG4PERL_CONF'} and -s $ENV{"LOG4PERL_CONF"} ) {
122
123
        # Check for web server level configuration first
124
        # In this case we ASSUME that you correctly arranged logfile
125
        # permissions. If not, log4perl will crash on you.
126
        # We will not parse apache files here.
127
        Log::Log4perl->init_once( $ENV{"LOG4PERL_CONF"} );
128
    }
129
    elsif ( C4::Context->config("log4perl_conf") ) {
130
131
        # Now look in the koha conf file. We only check the permissions of
132
        # the default logfiles. For the rest, we again ASSUME that
133
        # you arranged file permissions.
134
        my $conf = C4::Context->config("log4perl_conf");
135
        if ( $rv = _check_conf($conf) ) {
136
            Log::Log4perl->init_once($conf);
137
            return $rv;
138
        }
139
        else {
140
            return 0;
141
        }
142
    }
143
    else {
144
        # This means that you do not use log4perl currently.
145
        # We will not be forcing it.
146
        return 0;
147
    }
148
    return 1;    # if we make it here, log4perl did not crash :)
149
}
150
120
151
sub _check_conf {    # check logfiles in log4perl config (at initialization)
121
    my $log4perl_config =
152
    my $file = shift;
122
          exists $ENV{"LOG4PERL_CONF"}
153
    return if !-r $file;
123
              && $ENV{'LOG4PERL_CONF'}
154
    open my $fh, '<', $file;
124
           && -s $ENV{"LOG4PERL_CONF"}
155
    my @lines = <$fh>;
125
      # Check for web server level configuration first
156
    close $fh;
126
      # In this case we ASSUME that you correctly arranged logfile
157
    my @logs;
127
      # permissions. If not, log4perl will crash on you.
158
    foreach my $l (@lines) {
128
      ? $ENV{"LOG4PERL_CONF"}
159
        if ( $l =~ /(OPAC|INTRANET)\.filename\s*=\s*(.*)\s*$/i ) {
129
      : C4::Context->config("log4perl_conf");
160
130
161
            # we only check the two default logfiles, skipping additional ones
131
    # This will explode with the relevant error message if something is wrong in the config file
162
            return if !-w $2;
132
    return Log::Log4perl->init_once($log4perl_config);
163
            push @logs, $1 . ':' . $2;
164
        }
165
    }
166
    return if !@logs;    # we should find one
167
    return \@logs;
168
}
133
}
169
134
170
sub _recheck_logfile {    # recheck saved logfile when logging message
135
sub _recheck_logfile {    # recheck saved logfile when logging message
171
- 

Return to bug 25172