[Catalyst] Log::Log4perl::Catalyst

Alexander Hartmaier alexander.hartmaier at t-systems.at
Wed May 15 16:05:35 GMT 2013

On 2013-05-15 17:54, Duncan Garland wrote:

Has anybody got some examples about how to use this.

It looks like you just have to put the following lines in the main package =
before __PACKAGE__->setup():

use Log::Log4perl::Catalyst;

That works up to a point in that the log messages are formatted as I want. =
However they always go to the STDERR and not to the file given in log4perl.=
conf. I've used the conf file in a test, so I know it works outside Catalys=
t. I'm using the Catalyst development server, does that over-ride the logge=

The other thing is that I don't really want to hardcode the filename. It sh=
ould be in the application's conf file. However, if I just stick it in ther=
e as so:

  conf_file /var/www/mymercedesservice.co.uk/fcgi/catalyst/mbfl2/lib/mbfl2/=

I can't access it via __PACKAGE__->config->{Log4perl}->{conf_file};
until after setup() has run.

Does that matter?



That's how I do it in all of our Catalyst apps:

In My::App:

=3Ditem finalize_config

Initializes the logger after the config file merging and loading is done.


sub finalize_config {
    my $class =3D shift;

# Start the application

around 'prepare' =3D> sub {
    my $orig =3D shift;
    my $self =3D shift;


    my $c =3D $self->$orig(@_);

    Log::Log4perl::MDC->put( "username", $c->user->username )
        if $c->user_exists;

    return $c;

This assumes that the l4p config is in the app config file under 'log' e.g.=
 from one of my Config::General config files:

    log4perl.logger                                     "WARN, FILE, MAIL"
    log4perl.appender.FILE                              "Log::Log4perl::App=
    log4perl.appender.FILE.filename                     "/home/nac/log/nac-=
    log4perl.appender.FILE.utf8                         1
    log4perl.appender.FILE.syswrite                     1
    log4perl.appender.FILE.layout                       "Log::Log4perl::Lay=
    log4perl.appender.FILE.layout.ConversionPattern     "%d{yyyy-MM-dd HH:m=
m:ss} %-5p %X{username} %m%n"
    log4perl.appender.MAIL                              "Log::Dispatch::Ema=
    log4perl.appender.MAIL.Threshold                    ERROR
    log4perl.appender.MAIL.from                         "app at t-systems.at"<=
mailto:app at t-systems.at>
    log4perl.appender.MAIL.to                           "poor.bastard-aka-m=
e at ourcompany.com"<mailto:poor.bastard-aka-me at ourcompany.com>
    log4perl.appender.MAIL.subject                      "[NAC::Web::Request=
] errors"
    log4perl.appender.MAIL.buffered                     0
    log4perl.appender.MAIL.layout                       "PatternLayout"
    log4perl.appender.MAIL.layout.ConversionPattern     "%d{yyyy-MM-dd HH:m=
m:ss} %-5p %X{username} %m%n"

List: Catalyst at lists.scsys.co.uk<mailto: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/

T-Systems Austria GesmbH Rennweg 97-99, 1030 Wien
Handelsgericht Wien, FN 79340b
Notice: This e-mail contains information that is confidential and may be pr=
If you are not the intended recipient, please notify the sender and then
delete this e-mail immediately.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20130515/22014=

More information about the Catalyst mailing list