The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

LWP::UserAgent::Patch::LogResponse - Log raw HTTP responses

VERSION

This document describes version 0.11 of LWP::UserAgent::Patch::LogResponse (from Perl distribution LWP-UserAgent-Patch-LogResponse), released on 2017-06-26.

SYNOPSIS

use LWP::UserAgent::Patch::LogResponse
    -log_response_header  => 1, # default 1
    -log_response_body    => 1, # default 0
    -decode_response_body => 1, # default 1, turn off, e.g. to get raw gzipped content
;

# now all your LWP HTTP responses are logged

Sample script and output:

% TRACE=1 perl -MLog::ger::Output::Screen -MLWP::UserAgent::Patch::LogResponse \
  -MLWP::Simple -e'get "http://localhost:5000/"'
[261] HTTP response header:
200 OK
Date: Mon, 20 Aug 2012 07:47:46 GMT
Server: HTTP::Server::PSGI
Content-Length: 13
Content-Type: text/plain
Client-Date: Mon, 20 Aug 2012 07:47:46 GMT
Client-Peer: 127.0.0.1:5000
Client-Response-Num: 1

DESCRIPTION

This module patches LWP::UserAgent (which is used by LWP::Simple, WWW::Mechanize, among others) so that HTTP responses are logged using Log::ger.

Response body is logged in category LWP_Response_Body.* so it can be separated. For example, to dump response body dumps to directory instead of file:

use Log::ger::Output Composite => (
    category_level => {LWP_Response_Body => 'off'},
    outputs        => {
        Dir => {
            conf  => { path => "/path/to/dir" },
            level => 'off',
            category_level => {LWP_Response_Body => 'trace'},
        },
    }
);

FAQ

Why not subclass?

By patching, you do not need to replace all the client code which uses LWP (or WWW::Mechanize, etc).

HOMEPAGE

Please visit the project's homepage at https://metacpan.org/release/LWP-UserAgent-Patch-LogResponse.

SOURCE

Source repository is at https://github.com/perlancar/perl-LWP-UserAgent-Patch-LogResponse.

BUGS

Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=LWP-UserAgent-Patch-LogResponse

When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.

SEE ALSO

Use Net::HTTP::Methods::Patch::LogRequest to log raw HTTP requests being sent to servers.

AUTHOR

perlancar <perlancar@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2017, 2016, 2015, 2013, 2012 by perlancar@cpan.org.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.