NAME

Apache::LogFormat::Compiler - Compile LogFormat to perl-code

SYNOPSIS

use Apache::LogFormat::Compiler;

my $log_handler = Apache::LogFormat::Compiler->new("combined");
# my $log_handler = Apache::LogFormat::Compiler->new(
#     '%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-agent}i"'
# );
my $log = $log_handler->log_line(
    $env,
    $res,
    $length,
    $time
);

DESCRIPTION

Compile LogFormat to perl-code. For faster generating access_log line.

THIS IS A DEVELOPMENT RELEASE. API MAY CHANGE WITHOUT NOTICE.

METHOD

new($fmt:String)

Takes a format string (or a preset template combined or custom) to specify the log format. This middleware implements a subset of Apache's LogFormat templates:

%%    a percent sign
%h    REMOTE_ADDR from the PSGI environment, or -
%l    remote logname not implemented (currently always -)
%u    REMOTE_USER from the PSGI environment, or -
%t    [local timestamp, in default format]
%r    REQUEST_METHOD, REQUEST_URI and SERVER_PROTOCOL from the PSGI environment
%s    the HTTP status code of the response
%b    content length
%T    custom field for handling times in subclasses
%D    custom field for handling sub-second times in subclasses
%v    SERVER_NAME from the PSGI environment, or -
%V    HTTP_HOST or SERVER_NAME from the PSGI environment, or -
%p    SERVER_PORT from the PSGI environment
%P    the worker's process id

Some of these format fields are only supported by middleware that subclasses AccessLog.

In addition, custom values can be referenced, using %{name}, with one of the mandatory modifier flags i, o or t:

%{variable-name}i    HTTP_VARIABLE_NAME value from the PSGI environment
%{header-name}o      header-name header
%{time-format]t      localtime in the specified strftime format
log_line($env:HashRef,$res:ArrayRef,$length:Integer,$time:Integer): $log:String

PSGI-style $env and $res, Content-Length and the time taken to serve request in microseconds.

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.