kazeburo / apache-logformat-compiler Goto Github PK
View Code? Open in Web Editor NEWCompile LogFormat to perl-code
License: Other
Compile LogFormat to perl-code
License: Other
Hi Kazeburo
"%{Set-Cookie}o" only records the first Set-Cookie header contents.
but sending out multiple Set-Cookie headers for different cookies are quite common.
Could you please modify the program for this problem? thanks
I've been trying to make it possible to add extra formatting codes to Plack::Middleware::AccessLog -- see:
plack/Plack#387
plack/Plack#381
If I were to create a new middleware that used Apache::Format::Compiler internally, how would you suggest I proceed to let Apache::Format::Compiler accept new format codes? Would a patch similar to plack/Plack#381 be acceptable, that added configuration variables to store new codes?
This would be most of the code changes:
sub new {
my $class = shift;
my $fmt = shift || "combined";
$fmt = $formats{$fmt} if exists $formats{$fmt};
+
+ my %opts = @_;
my $self = bless {
fmt => $fmt,
+ block_handlers => $opts{block_handlers} || {},
+ char_handlers => $opts{char_handlers} || {},
}, $class;
$self->compile();
return $self;
}
my $block_handler = sub {
my($block, $type) = @_;
my $cb;
if ($type eq 'i') {
$block =~ s/-/_/g;
$cb = q!_string($env->{"HTTP_" . uc('!.$block.q!')})!;
} elsif ($type eq 'o') {
$cb = q!_string(scalar Plack::Util::headers($res->[1])->get('!.$block.q!'))!;
} elsif ($type eq 't') {
$cb = q!"[" . _strftime('!.$block.q!', localtime($time)) . "]"!;
+ } elsif (my $handler = $self->block_handlers->{$type}) {
+ $cb = $handler;
+ } else {
Carp::croak("{$block}$type not supported");
$cb = "-";
}
return q|! . | . $cb . q|
. q!|;
};
my $char_handler = sub {
my $char = shift;
my $cb = $char_handler{$char};
+ unless ($cb) {
+ $cb = $self->char_handlers->{$char};
+ }
unless ($cb) {
Carp::croak "\%$char not supported.";
return "-";
}
q|! . | . $cb . q|
. q!|;
};
On 5.25.10 with -Ddefault_inc_excludes_dot ( scheduled to be default real-soon-now )
Installing /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/site_perl/5.25.10/x86_64-linux/.meta/POSIX-strftime-Compiler-0.42/MYMETA.json
Installing /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/site_perl/5.25.10/x86_64-linux/.meta/POSIX-strftime-Compiler-0.42/install.json
Building and testing Apache-LogFormat-Compiler-0.33
Building Apache-LogFormat-Compiler
Can't locate t/Req2PSGI.pm in @INC (you may need to install the t::Req2PSGI module) (@INC contains: /home/kent/.cpanm/work/1488802154.20749/Apache-LogFormat-Compiler-0.33/blib/lib /home/kent/.cpanm/work/1488802154.20749/Apache-LogFormat-Compiler-0.33/blib/arch /home/kent/.cpanm/work/1488802154.20749/Apache-LogFormat-Compiler-0.33/_build/lib /home/kent/.cpanm/work/1488802154.20749/Apache-LogFormat-Compiler-0.33/blib/lib /home/kent/.cpanm/work/1488802154.20749/Apache-LogFormat-Compiler-0.33/blib/arch /home/kent/.cpanm/work/1488802154.20749/Apache-LogFormat-Compiler-0.33/_build/lib /home/kent/.cpanm/work/1488802154.20749/Apache-LogFormat-Compiler-0.33/blib/lib /home/kent/.cpanm/work/1488802154.20749/Apache-LogFormat-Compiler-0.33/blib/arch /home/kent/.cpanm/work/1488802154.20749/Apache-LogFormat-Compiler-0.33/_build/lib /home/kent/.cpanm/work/1488802154.20749/Apache-LogFormat-Compiler-0.33/blib/lib /home/kent/.cpanm/work/1488802154.20749/Apache-LogFormat-Compiler-0.33/blib/arch /home/kent/.cpanm/work/1488802154.20749/Apache-LogFormat-Compiler-0.33/_build/lib /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/site_perl/5.25.10/x86_64-linux /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/site_perl/5.25.10 /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/5.25.10/x86_64-linux /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/5.25.10) at t/03_extra.t line 4.
BEGIN failed--compilation aborted at t/03_extra.t line 4.
t/03_extra.t ....
Dubious, test returned 2 (wstat 512, 0x200)
No subtests run
Can't locate t/Req2PSGI.pm in @INC (you may need to install the t::Req2PSGI module) (@INC contains: /home/kent/.cpanm/work/1488802154.20749/Apache-LogFormat-Compiler-0.33/blib/lib /home/kent/.cpanm/work/1488802154.20749/Apache-LogFormat-Compiler-0.33/blib/arch /home/kent/.cpanm/work/1488802154.20749/Apache-LogFormat-Compiler-0.33/_build/lib /home/kent/.cpanm/work/1488802154.20749/Apache-LogFormat-Compiler-0.33/blib/lib /home/kent/.cpanm/work/1488802154.20749/Apache-LogFormat-Compiler-0.33/blib/arch /home/kent/.cpanm/work/1488802154.20749/Apache-LogFormat-Compiler-0.33/_build/lib /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/site_perl/5.25.10/x86_64-linux /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/site_perl/5.25.10 /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/5.25.10/x86_64-linux /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/5.25.10) at t/01_basic.t line 4.
BEGIN failed--compilation aborted at t/01_basic.t line 4.
t/01_basic.t ....
Dubious, test returned 2 (wstat 512, 0x200)
No subtests run
Can't locate t/Req2PSGI.pm in @INC (you may need to install the t::Req2PSGI module) (@INC contains: /home/kent/.cpanm/work/1488802154.20749/Apache-LogFormat-Compiler-0.33/blib/lib /home/kent/.cpanm/work/1488802154.20749/Apache-LogFormat-Compiler-0.33/blib/arch /home/kent/.cpanm/work/1488802154.20749/Apache-LogFormat-Compiler-0.33/_build/lib /home/kent/.cpanm/work/1488802154.20749/Apache-LogFormat-Compiler-0.33/blib/lib /home/kent/.cpanm/work/1488802154.20749/Apache-LogFormat-Compiler-0.33/blib/arch /home/kent/.cpanm/work/1488802154.20749/Apache-LogFormat-Compiler-0.33/_build/lib /home/kent/.cpanm/work/1488802154.20749/Apache-LogFormat-Compiler-0.33/blib/lib /home/kent/.cpanm/work/1488802154.20749/Apache-LogFormat-Compiler-0.33/blib/arch /home/kent/.cpanm/work/1488802154.20749/Apache-LogFormat-Compiler-0.33/_build/lib /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/site_perl/5.25.10/x86_64-linux /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/site_perl/5.25.10 /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/5.25.10/x86_64-linux /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/5.25.10) at t/02_custom.t line 4.
BEGIN failed--compilation aborted at t/02_custom.t line 4.
t/02_custom.t ...
Dubious, test returned 2 (wstat 512, 0x200)
No subtests run
t/00_compile.t .. ok
Can't locate t/Req2PSGI.pm in @INC (you may need to install the t::Req2PSGI module) (@INC contains: /home/kent/.cpanm/work/1488802154.20749/Apache-LogFormat-Compiler-0.33/blib/lib /home/kent/.cpanm/work/1488802154.20749/Apache-LogFormat-Compiler-0.33/blib/arch /home/kent/.cpanm/work/1488802154.20749/Apache-LogFormat-Compiler-0.33/_build/lib /home/kent/.cpanm/work/1488802154.20749/Apache-LogFormat-Compiler-0.33/blib/lib /home/kent/.cpanm/work/1488802154.20749/Apache-LogFormat-Compiler-0.33/blib/arch /home/kent/.cpanm/work/1488802154.20749/Apache-LogFormat-Compiler-0.33/_build/lib /home/kent/.cpanm/work/1488802154.20749/Apache-LogFormat-Compiler-0.33/blib/lib /home/kent/.cpanm/work/1488802154.20749/Apache-LogFormat-Compiler-0.33/blib/arch /home/kent/.cpanm/work/1488802154.20749/Apache-LogFormat-Compiler-0.33/_build/lib /home/kent/.cpanm/work/1488802154.20749/Apache-LogFormat-Compiler-0.33/blib/lib /home/kent/.cpanm/work/1488802154.20749/Apache-LogFormat-Compiler-0.33/blib/arch /home/kent/.cpanm/work/1488802154.20749/Apache-LogFormat-Compiler-0.33/_build/lib /home/kent/.cpanm/work/1488802154.20749/Apache-LogFormat-Compiler-0.33/blib/lib /home/kent/.cpanm/work/1488802154.20749/Apache-LogFormat-Compiler-0.33/blib/arch /home/kent/.cpanm/work/1488802154.20749/Apache-LogFormat-Compiler-0.33/_build/lib /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/site_perl/5.25.10/x86_64-linux /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/site_perl/5.25.10 /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/5.25.10/x86_64-linux /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/5.25.10) at t/04_tz.t line 7.
BEGIN failed--compilation aborted at t/04_tz.t line 7.
t/04_tz.t .......
Dubious, test returned 2 (wstat 512, 0x200)
No subtests run
Test Summary Report
-------------------
t/03_extra.t (Wstat: 512 Tests: 0 Failed: 0)
Non-zero exit status: 2
Parse errors: No plan found in TAP output
t/01_basic.t (Wstat: 512 Tests: 0 Failed: 0)
Non-zero exit status: 2
Parse errors: No plan found in TAP output
t/02_custom.t (Wstat: 512 Tests: 0 Failed: 0)
Non-zero exit status: 2
Parse errors: No plan found in TAP output
t/04_tz.t (Wstat: 512 Tests: 0 Failed: 0)
Non-zero exit status: 2
Parse errors: No plan found in TAP output
Files=5, Tests=1, 0 wallclock secs ( 0.04 usr 0.01 sys + 0.26 cusr 0.06 csys = 0.37 CPU)
Result: FAIL
Failed 4/5 test programs. 0/1 subtests failed.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.