GithubHelp home page GithubHelp logo

apache-logformat-compiler's People

Contributors

astj avatar dex4er avatar fschlich avatar kazeburo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

apache-logformat-compiler's Issues

Formats are not extensible

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!|;
    };

Fails tests without '.' in @INC

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.