[Catalyst] log4perl and logging request parameters

Bill Moseley moseley at hank.org
Thu Nov 29 04:21:30 GMT 2012


I use a log4perl config file, and I have two appenders -- one is for INFO
and above and is a screen appender (web server logs), and the other is for
ERROR and is directed to a separate file.

For *only *WARN and above messages I want to include a dump of request
parameters in the log message.   That is, for INFO messages I don't want to
include the parameters.

That's pretty easy for normal exceptions.   At the end of a request I look
for $c->error and when found I use Log::Log4perl::MDC->put( params =3D>
Dumper $c->req->parameters ) to include the params in the log using
%X{params}.   (Except, I sanitize the params first -- e.g. replace values
that match /password/).

I'd like to find a more generic way, and something that will work for
calling $c->log->warn and $c->log->error directly, too.   (I also trap
__WARN__ and __DIE__ to use log4perl and dump a stack trace).

Again, I don't want the params in all messages, so I don't want to
set Log4perl::MDC->put( params =3D> $dump ) at the start of each request.  =
 I
only want to do that for WARN and ERROR messages.

Should I put $c->req->parameters in a global at the start of each request
and then wrap the warn() and error() methods and set the MDC params in
those methods?

Monkey-patch (redefined) the warn() and error() log methods each request
with the current params?

Neither of those sound that great.  Is there an approach I'm missing?

Thanks,

-- =

Bill Moseley
moseley at hank.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20121128/e9c92=
1b0/attachment.htm


More information about the Catalyst mailing list