[Catalyst] Log4Perl and Catalyst startup routing table

Scott Thomson smoothhound at gmail.com
Fri Nov 14 09:23:28 GMT 2014


On Thu Nov 13 2014 at 20:22:51 Aristotle Pagaltzis <pagaltzis at gmx.de> wrote:

> Hi Adam,
>
> * Adam Witney <awitney at sgul.ac.uk> [2014-11-13 12:45]:
> > I saw this post, but I 'm not sure I can use it to get the Catalyst
> > normal startup output in my logs. Is this possible?
>
> The problem with redirecting this stuff is that Catalyst produces the
> debug output very early during its startup, before it has loaded any
> extensions or plugins, so the logging facilities are the built-in stuff.
> (Hm, maybe it is possible to load the logging-related modules yourself
> and then hack them in with BEGIN or some such.) The code to produce this
> output is part of the startup code and not well accessible separately
> (which is the whole reason for CatalystX::Info after all).
>
>
>
I've had success with this sort of approach, by overriding finalize_config
in the base class:

 =head2 finalize_config

After config merging is complete initialise log4perl as our logger and
enrich the available version info

=cut

sub finalize_config {
  my $class = shift;

  $class->next::method(@_);

  $class->log( Log::Log4perl::Catalyst->new( $class->config->{logfile} ) );

  my $visible_version = $class->_describe_version;
  $class->config->{version} = $visible_version;
  $class->log->info( "Starting version: [" . $visible_version->{name} . "]"
);
}

Something like that should do what you need.

--
Scott
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.scsys.co.uk/pipermail/catalyst/attachments/20141114/61c9e477/attachment.htm>


More information about the Catalyst mailing list