perlloggingconfigurationcatalystlog4perl

Catalyst Log4perl: configure config file location from app config


In a Catalyst app, I need to specify the Log4perl's config file location. All the examples I could find suggest that I should do that from code. However, I would like to be able to specify it in the app config file. This would allow me to use different log configs for different environments and manage all that from a single file. I would also like to be able to set log levels from app config file.

However, there seems to be no documented way of configuring the logger from the app config file. I tried multiple variations of syntax, but none was picked up by Catalyst. It is also impossible to set the correct config file name from MyApp.pm (main app module), as configuration is not yet available when module code is run.

Debugging the logger initialization code also didn't help. The only real way I am considering now is to require a config file from MyApp.pm, which would include the necessary configuration.

The questions thus are:

  1. Is there a way to specify the Log4perl config file location from Catalyst config file?
  2. Is there a way to specify log levels from a config file?

Solution

  • I thought I'd googled enough, but apparently I hadn't.

    __PACKAGE__->setup();
    __PACKAGE__->log(Log::Log4perl::Catalyst->new(__PACKAGE__->path_to(__PACKAGE__->config->{Log}->{config_file})->stringify));
    

    (ref http://www.gossamer-threads.com/lists/catalyst/users/31271).

    And as for log levels: they are defined in the actual Log4perl config file.