|
NAMEApache::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
);
DESCRIPTIONCompile a log format string to perl-code. For faster generation of access_log lines. METHOD
ABOUT POSIX::strftime::CompilerThis 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 STRINGApache::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. AUTHORMasahiro Nagano <kazeburo@gmail.com> SEE ALSOPlack::Middleware::AccessLog, <http://httpd.apache.org/docs/2.2/mod/mod_log_config.html> LICENSECopyright (C) Masahiro Nagano This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
|