[Catalyst] Using Log4perl -- setting caller()

Quinn Weaver quinn at fairpath.com
Tue Jul 3 18:49:08 GMT 2007


On Mon, Jul 02, 2007 at 08:04:40AM -0700, Bill Moseley wrote:

> Also, I'd like to include request-specific items in the lot message.
> 
> What would be the best way to get $c->req to the logger?  I considered
> creating $c->info, $c->warn, and $c->error methods that add the
> request data I would like to see to the $message and then forward onto
> $c->log->$level.

In log4perl.conf:

log4perl.appender.myAppenderName.layout.ConversionPattern \
    = process %8P: client %X{ip}: %X{uri}: %5p: %m: %T

In sub auto (Controller/Root.pm in my setup):

sub auto : Private {
    my ( $self, $c ) = @_;

    # Add some info to all log messages for this request:
    warn 'client_ip ', $c->req->address();
    Log::Log4perl::MDC->put( 'ip',        $c->req->address() );
    Log::Log4perl::MDC->put( 'uri',       $c->req->uri() );   

-- 
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