Andrew Rodland
and 2 contributors


Catalyst::Plugin::AccessLog - Request logging from within Catalyst


version 1.05


Requires Catalyst 5.8 or above.

    # In lib/ context
    use Catalyst qw(
        ... other plugins here ...

        'Plugin::AccessLog' => {
            formatter => {
              format => '%[time] %[remote_address] %[path] %[status] %[size]',
              time_format => '%c',
              time_zone => 'America/Chicago',



This plugin isn't for "debug" logging. Instead it enables you to create "access logs" from within a Catalyst application instead of requiring a webserver to do it for you. It will work even with Catalyst debug logging turned off (but see enable_stats below).


All configuration is optional; by default the plugin will log to STDERR in a format compatible with the "Common Log Format" (


Default: \*STDERR

Where to log to. If target is a filehandle or something that isa("IO::Handle"), lines of logging information will be printed to it. If target is an object with an info method it's assumed to be a logging object (e.g. Log::Dispatch or Log::Log4perl) and lines will be passed to the info method. If it's a CODE ref then it will be called with each line of logging output. If it's an unblessed scalar it will be interpreted as a filename and the plugin will try to open it for append and write lines to it.


Default: { class => "Catalyst::Plugin::AccessLog::Formatter" }

The formatter to use. Defaults to the Formatter class included in this distribution. This option must be a hashref. The class option is taken as the name of the class to use as the formatter; all other keys are passed to that class's constructor. See Catalyst::Plugin::AccessLog::Formatter for the keys supported by that module.


Default: true

Catalyst::Plugin::AccessLog works without regard to Catalyst's debug logging option. However, the time-related escapes are only available if the Catalyst::Stats statistics collection is enabled, and by default stats are tied to the value of the debug flag. If this option is set, stats will be enabled for the application regardless of the -Stats or -Debug flags, or the MYAPP_STATS or MYAPP_DEBUG environment variables.


Logging to $c->log

It is generally not recommended to write the access log to $c->log, especially if static file handling is enabled. However, there might be a good reason to do it somewhere. If the logging target is a coderef, it will receive $c as its second argument. You can log to $c->log with:

    target => sub { pop->log->info(shift) }

Don't store $c anywhere that persists after the lifetime of the coderef or bad things will happen to you and everyone you know.



  • Andrew Rodland <>

  • Murray <>


This software is copyright (c) 2012 by Andrew Rodland.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.