[Catalyst] Using Log4perl -- setting caller()
Quinn Weaver
quinn at fairpath.com
Tue Jul 3 23:14:52 GMT 2007
On Mon, Jul 02, 2007 at 08:04:40AM -0700, Bill Moseley wrote:
> I have a few questions about using Log4perl. I want to send warnings
> to the logger and also include some request info.
>
> I'm using Catalyst::Log::Log4perl, and it uses caller() to set the
> logger category.
>
> Now, one thing I was playing with is having warnings sent to log4perl.
> There's C::P::LogWarnings but it uses Class:C3 which doesn't agree
> with the Session plugins.
>
> So In a plugin to seutp Log4perl I modified the code from
> C::P::LogWarnings:
>
> sub handle_request {
> my $c = shift;
> return $c->NEXT::handle_request( @_ )
> unless $c->config->{log4perl}{log_warnings};
>
> return do {
> local $SIG{__WARN__} = sub {
> my $warning = shift;
> chomp $warning;
> $c->log->warn( $warning );
> };
> $c->NEXT::handle_request( @_ );
> };
> }
>
> Now, the problem with that is $c->log->warn uses caller() so errors
> are reported from that sub, not from where warn was called. So, need
> a way to use (IIRC) caller(1) instead in that case.
Talked to Bill off-list, and this problem appears to be spurious.
That is, the messages are actually reported as coming from the right line,
after all.
--
Quinn Weaver, independent contractor | President, San Francisco Perl Mongers
http://fairpath.com/quinn/resume/ | http://sf.pm.org/
510-520-5217
More information about the Catalyst
mailing list