The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Apache::LogFormat::Compiler - Compile a log format string to perl-code

SYNOPSIS

use Apache::LogFormat::Compiler;

my $log_handler = Apache::LogFormat::Compiler->new("combined");
my $log = $log_handler->log_line(
    $env,
    $res,
    $length,
    $reqtime,
    $time
);

DESCRIPTION

Compile a log format string to perl-code. For faster generation of access_log lines.

METHOD

ABOUT POSIX::strftime::Compiler

This module uses POSIX::strftime::Compiler for generate datetime string. POSIX::strftime::Compiler provides GNU C library compatible strftime(3). But this module will not affected by the system locale. This feature is useful when you want to write loggers, servers and portable applications.

ADD CUSTOM FORMAT STRING

Apache::LogFormat::Compiler allows one to add a custom format string

my $log_handler = Apache::LogFormat::Compiler->new(
    '%z %{HTTP_X_FORWARDED_FOR|REMOTE_ADDR}Z',
    char_handlers => +{
        'z' => sub {
            my ($env,$req) = @_;
            return $env->{HTTP_X_FORWARDED_FOR};
        }
    },
    block_handlers => +{
        'Z' => sub {
            my ($block,$env,$req) = @_;
            # block eq 'HTTP_X_FORWARDED_FOR|REMOTE_ADDR'
            my ($main, $alt) = split('\|', $args);
            return exists $env->{$main} ? $env->{$main} : $env->{$alt};
        }
    },
);

Any single letter can be used, other than those already defined by Apache::LogFormat::Compiler. Your sub is called with two or three arguments: the content inside the {} from the format (block_handlers only), the PSGI environment ($env), and the ArrayRef of the response. It should return the string to be logged.

AUTHOR

Masahiro Nagano kazeburo@gmail.com

SEE ALSO

Plack::Middleware::AccessLog, http://httpd.apache.org/docs/2.2/mod/mod_log_config.html

LICENSE

Copyright (C) Masahiro Nagano

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