Giter VIP home page Giter VIP logo

plack-middleware-trafficlog's Introduction

Build Status

NAME

Plack::Middleware::TrafficLog - Log headers and body of HTTP traffic

SYNOPSIS

# In app.psgi
use Plack::Builder;

builder {
    enable "TrafficLog", with_body => 1;
};

DESCRIPTION

This middleware logs the request and response messages with detailed information about headers and body.

The example log:

[08/Aug/2012:16:59:47 +0200] [164836368] [127.0.0.1 -> 0:5000] [Request ]
|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 which have delayed response. In that case each chunk is logged separately and shares the same unique ID number and headers.

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

CONFIGURATION

  • logger

      # traffic.l4p
      log4perl.logger.traffic = DEBUG, LogfileTraffic
      log4perl.appender.LogfileTraffic = Log::Log4perl::Appender::File
      log4perl.appender.LogfileTraffic.filename = traffic.log
      log4perl.appender.LogfileTraffic.layout = PatternLayout
      log4perl.appender.LogfileTraffic.layout.ConversionPattern = %m{chomp}%n
    
      # app.psgi
      use Log::Log4perl qw(:levels get_logger);
      Log::Log4perl->init('traffic.l4p');
      my $logger = get_logger('traffic');
    
      enable "Plack::Middleware::TrafficLog",
          logger => sub { $logger->log($INFO, join '', @_) };
    

    Sets a callback to print log message to. It prints to psgi.errors output stream by default.

  • with_request

    The false value disables logging of request message.

  • with_response

    The false value disables logging of response message.

  • with_date

    The false value disables logging of current date.

  • with_body

    The true value enables logging of message's body.

  • with_all_chunks

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

  • eol

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

  • body_eol

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

SEE ALSO

Plack, Plack::Middleware::AccessLog.

BUGS

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

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

If you find the bug or want to implement new features, please report it at http://github.com/dex4er/perl-Plack-Middleware-TrafficLog/issues

The code repository is available at http://github.com/dex4er/perl-Plack-Middleware-TrafficLog

AUTHOR

Piotr Roszatycki [email protected]

LICENSE

Copyright (c) 2012, 2014 Piotr Roszatycki [email protected].

This is free software; you can redistribute it and/or modify it under the same terms as perl itself.

See http://dev.perl.org/licenses/artistic.html

plack-middleware-trafficlog's People

Contributors

dex4er avatar

Watchers

 avatar  avatar  avatar

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.