[Catalyst] Populate Log4perl config from Catalyst perl hooks

Anthony Gladdish anthony.gladdish at newcastle.ac.uk
Mon Apr 22 10:25:41 GMT 2013


I'm trying to add values to the Log4perl configuration from my Catalyst config, via Perl hooks as per https://metacpan.org/module/Log::Log4perl#Perl-Hooks-in-the-Configuration-File 

My main Cat app file is:

	package MyApp::Cat;

	use strict;
	use warnings;
	use Catalyst::Runtime '5.70';
	use Log::Log4perl::Catalyst;


	sub my_test_hook {
	    	my $self = shift;
		return $self->config->{log4perl_conversion_pattern}; # E.g. '[%d] [MyApp::Cat] [%p] %m%n'.
	__PACKAGE__->log( Log::Log4perl::Catalyst->new( __PACKAGE__->path_to(__PACKAGE__->config->{path_to_log4perl_conf})->stringify ) );

Then in my Log4perl config:

	log4perl.appender.LOGFILE.layout.ConversionPattern=\sub { return MyApp::Cat::my_test_hook(); }

Unfortunately, this only prints " \sub { return MyApp::Cat::my_test_hook(); } " in my log file!

Can anyone see how I may be able to fix this?


More information about the Catalyst mailing list