[Catalyst] How to enhance Log4Perl log-files about the loggend in user ($c->user->id)?

Jon Schutz jon+catalyst at youramigo.com
Thu Jul 23 14:25:08 GMT 2009


Somewhere early on on the request cycle do

Log::Log4perl::MDC->put( 'user' => $user );

then insert it into your log messages via your Log4perl configuration
such as:

log4perl.appender.Logfile.layout.ConversionPattern: "%d %-5p %c -
USER:%X{user} - %m%n"

Christoph Metz wrote:
> Hi,
> 
> i got a Catalyst-App which inits a session on the startpage, after a
> user logged sucessfully in with his login-data. Now, i also use
> Log4Perl to do extensive logging, as far as the app is enough tested. so
> i use the log4perl conf file this way:
> 
> __PACKAGE__->log(Catalyst::Log::Log4perl->new(__PACKAGE__->config->{home}.'/log.conf'));
> 
> where log.conf logs all data into a file myapp.log. There are many
> useful cspecs to show really exact log-entrys but one is missing,
> i want to see which debug/error/warn message was logged by which user.
> so how to pass the logged in user ($c->user->id) into the
> log4perl log-files?
> custom cspecs like descripted on CPAN
> Log::Log4Perl::Layout::PatternLayout are not able to access the
> namespace of my app,
> or at least i am not able to pass the context to the custom-cspecs sub
> in the log4perl conf-file :(
> 
> 
> 
> _______________________________________________
> List: Catalyst at lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/



More information about the Catalyst mailing list