You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Graf László <gr...@axis.hu> on 2004/04/20 08:35:10 UTC

Log::Log4perl

Hi gurus

I have the following configuration:

    UHU-Linux 1.1 (www.uhulinux.hu)
    httpd-2.0.49
    perl 5.8.3
    mod_perl-1.99_13
    Log::Log4perl 0.41

The problem is that, the Log::Log4perl used within test.pl (see below)
works fine, entering the "test message" into the /var/log/log4perl.log
file, each time when I run x.pl. Used within RequestHandler.pm (see below)
it does not work.

What is wrong ?
Thank you.




RequestHandler.pm
-----------------
package GL::BASE::RequestHandler;
@ISA = qw();
use Log::Log4perl;
Log::Log4perl::init('/etc/log4perl.conf');
$logger = Log::Log4perl->get_logger('GL::BASE::RequestHandler');
sub handler ($$) {
	my($r) = @_;
	$logger->error("in");
	$logger->error("out");
	return 0;
}
1;
#__END__


log4perl.conf
-------------
log4perl.rootLogger=ERROR, LOGFILE
log4perl.appender.LOGFILE=Log::Log4perl::Appender::File
log4perl.appender.LOGFILE.filename=/var/log/log4perl.log
log4perl.appender.LOGFILE.mode=append
log4perl.appender.LOGFILE.layout=PatternLayout
log4perl.appender.LOGFILE.layout.ConversionPattern=[%r] %F %L %c - %m%n


httpd.conf
----------
PerlInitHandler Apache::Reload
# PerlSetVar ReloadDebug On
# PerlSetVar ReloadModules "GL::*"
Alias /p/ /proba/
<Location /proba/>
      SetHandler perl-script
      PerlHandler GL::BASE::RequestHandler->handler
</Location>


test.pl
-----
#!/usr/bin/perl
use Log::Log4perl;
Log::Log4perl::init('/etc/log4perl.conf');
$logger = Log::Log4perl->get_logger('GL::PSP::RequestHandler');
x();
sub x {
	$logger->error("test message");
	return 0;
}

-- 
Graf László


-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: Log::Log4perl

Posted by Stas Bekman <st...@stason.org>.
Graf László wrote:
> Hi gurus
> 
> I have the following configuration:
> 
>    UHU-Linux 1.1 (www.uhulinux.hu)
>    httpd-2.0.49
>    perl 5.8.3
>    mod_perl-1.99_13
>    Log::Log4perl 0.41

Graf, please always submit problem reports as explained here:
http://perl.apache.org/bugs/

> The problem is that, the Log::Log4perl used within test.pl (see below)
> works fine, entering the "test message" into the /var/log/log4perl.log
> file, each time when I run x.pl. Used within RequestHandler.pm (see below)
> it does not work.
> 
> What is wrong?

What does $logger->error do under the hood? Should you check the success of 
this call and log an error if it fails? If not if it thinks it succeeds then 
it probably has something to do with filehanle redirection. Have you checked 
t/logs/error_log (in case Log::Log4perl prints via STDERR)

> RequestHandler.pm
> -----------------
> package GL::BASE::RequestHandler;
> @ISA = qw();
> use Log::Log4perl;
> Log::Log4perl::init('/etc/log4perl.conf');
> $logger = Log::Log4perl->get_logger('GL::BASE::RequestHandler');
> sub handler ($$) {

Under mod_perl 2, this needs to be written as:

   sub handler : method {

if you want to use object handlers. Please read:
http://perl.apache.org/docs/2.0/user/porting/compat.html#Method_Handlers

>     my($r) = @_;

and even under mod_perl that would be wrong, since a class would be the first 
argument there. I guess you did it because it wasn't giving you the class 
argument.

>     $logger->error("in");
>     $logger->error("out");
>     return 0;
> }

is this handler invoked at all? It doesn't send any response. Add some warn 
"foo" so you know it was called.

> httpd.conf
> ----------
> PerlInitHandler Apache::Reload
> # PerlSetVar ReloadDebug On
> # PerlSetVar ReloadModules "GL::*"
> Alias /p/ /proba/
> <Location /proba/>
>      SetHandler perl-script
>      PerlHandler GL::BASE::RequestHandler->handler

That should be PerlResponseHandler (unrelated to your problem). See the same 
doc quoted above.

> </Location>


__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html