Plack-Middleware-TrafficLog

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN


* Bugfix for typo that shows some warnings on Perl 5.22.

0.0400  2014-06-28      Piotr Roszatycki <dexter@cpan.org>

* POSIX::strftime::Compiler replaces POSIX::strftime::GNU

0.0300  2014-06-28      Piotr Roszatycki <dexter@cpan.org>

* The body of request and response is not logged by default.
* New option: with_all_chunks. For streaming reponses only first chunk is
  logged by default.
* Requires POSIX::strftime::GNU

0.0202  2012-08-17      Piotr Roszatycki <dexter@cpan.org>

* Correct timezone on systems where strftime doesn't support %z.
* Log also REMOTE_PORT if is defined.

0.0201  2012-08-08      Piotr Roszatycki <dexter@cpan.org>

README  view on Meta::CPAN

        |GET / HTTP/1.1|Connection: TE, close|Host: localhost:5000|TE: deflate,gzi
        p;q=0.3|User-Agent: lwp-request/6.03 libwww-perl/6.03||
        [08/Aug/2012:16:59:47 +0200] [164836368] [127.0.0.1 <- 0:5000] [Response]
        |HTTP/1.0 200 OK|Content-Type: text/plain||Hello World

    This module works also with applications that have delayed response. In
    that case, each chunk is logged separately and shares the same unique
    ID number and headers.

    The body of the request and response is not logged by default. For
    streaming responses, only the first chunk is logged by default.

SEE ALSO

    Plack, Plack::Middleware::AccessLog.

BUGS

    This module has an unstable API and it can be changed in the future.

    The log file can contain binary data if the PSGI server provides binary

lib/Plack/Middleware/TrafficLog.pm  view on Meta::CPAN

    p;q=0.3|User-Agent: lwp-request/6.03 libwww-perl/6.03||
    [08/Aug/2012:16:59:47 +0200] [164836368] [127.0.0.1 <- 0:5000] [Response]
    |HTTP/1.0 200 OK|Content-Type: text/plain||Hello World

=for markdown ```

This module works also with applications that have delayed response. In that
case, each chunk is logged separately and shares the same unique ID number and
headers.

The body of the request and response is not logged by default. For streaming
responses, only the first chunk is logged by default.

=for readme stop

=cut

use 5.008;

use strict;
use warnings;

lib/Plack/Middleware/TrafficLog.pm  view on Meta::CPAN

=item with_date

The false value disables logging of the current date.

=item with_body

The true value enables logging of the message's body.

=item with_all_chunks

The true value enables logging of every chunk for streaming responses.

=item eol

Sets the line separator for the message's headers and the body. The default
value is the pipe character C<|>.

=item body_eol

Sets the line separator for message's body only. The default is the space
character C< >. The default value is used only if B<eol> is also undefined.

t/100_trafficlog.t  view on Meta::CPAN

        is @Log, 2, 'delayed [lines]';
        like $Log[0],
            qr{^\[\d{2}/\S+/\d{4}:\d{2}:\d{2}:\d{2} \S+\] \[\d+\] \[127.0.0.1:\d+ -> example.com:80\] \[Request \] \|POST / HTTP/1.1\|Host: example.com\|Content-Length: 10\|Content-Type: text/plain\|\|TEST TEST $},
            'delayed [0]';
        like $Log[1],
            qr{^\[\d{2}/\S+/\d{4}:\d{2}:\d{2}:\d{2} \S+\] \[\d+\] \[127.0.0.1:\d+ <- example.com:80\] \[Response\] \|HTTP/1.0 200 OK\|Content-Type: text/plain\|\|OK OK $},
            'delayed [1]';
    }

    {
        my $app_streaming = sub {
            return sub {
                my ($responder) = @_;
                my $writer = $responder->([200, ['Content-Type' => 'text/plain']]);
                $writer->write("OK\n");
                $writer->write("OK\n");
                $writer->close;
                return;
            };
        };

        local @Log;
        my $res = $test->($app_streaming, with_body => 1)->($req);
        is $res->code, 200, 'response code';
        is $res->content, "OK\nOK\n", 'response content';
        is @Log, 2, 'streaming [lines]';
        like $Log[0],
            qr{^\[\d{2}/\S+/\d{4}:\d{2}:\d{2}:\d{2} \S+\] \[\d+\] \[127.0.0.1:\d+ -> example.com:80\] \[Request \] \|POST / HTTP/1.1\|Host: example.com\|Content-Length: 10\|Content-Type: text/plain\|\|TEST TEST $},
            'streaming [0]';
        like $Log[1],
            qr{^\[\d{2}/\S+/\d{4}:\d{2}:\d{2}:\d{2} \S+\] \[\d+\] \[127.0.0.1:\d+ <- example.com:80\] \[Response\] \|HTTP/1.0 200 OK\|Content-Type: text/plain\|\|OK $},
            'streaming [1]';
    }

    {
        my $app_streaming = sub {
            return sub {
                my ($responder) = @_;
                my $writer = $responder->([200, ['Content-Type' => 'text/plain']]);
                $writer->write("OK\n");
                $writer->write("OK\n");
                $writer->close;
                return;
            };
        };

        local @Log;
        my $res = $test->($app_streaming, with_body => 1, with_all_chunks => 1)->($req);
        is $res->code, 200, 'response code';
        is $res->content, "OK\nOK\n", 'response content';
        is @Log, 3, 'streaming [lines]';
        like $Log[0],
            qr{^\[\d{2}/\S+/\d{4}:\d{2}:\d{2}:\d{2} \S+\] \[\d+\] \[127.0.0.1:\d+ -> example.com:80\] \[Request \] \|POST / HTTP/1.1\|Host: example.com\|Content-Length: 10\|Content-Type: text/plain\|\|TEST TEST $},
            'streaming [0]';
        like $Log[1],
            qr{^\[\d{2}/\S+/\d{4}:\d{2}:\d{2}:\d{2} \S+\] \[\d+\] \[127.0.0.1:\d+ <- example.com:80\] \[Response\] \|HTTP/1.0 200 OK\|Content-Type: text/plain\|\|OK $},
            'streaming [1]';
        like $Log[2],
            qr{^\[\d{2}/\S+/\d{4}:\d{2}:\d{2}:\d{2} \S+\] \[\d+\] \[127.0.0.1:\d+ <- example.com:80\] \[Response\] \|HTTP/1.0 200 OK\|Content-Type: text/plain\|\|OK $},
            'streaming [2]';
    }

    {
        my $app_static_499 = sub {
            [499, ['Content-Type' => 'text/plain'], ["Unknown error\n"]]
        };

        {
            local @Log;
            my $res = $test->($app_static_499, with_body => 1)->($req);



( run in 0.253 second using v1.01-cache-2.11-cpan-4d50c553e7e )