Logging LWP HTTP requests with Log::Any

Yet another effort to add Log::Any logging to a popular module, this time LWP. Presenting: Net::HTTP::Methods::patch::log_request. Inside, tt's currently just a wrapper for format_request() method in Net::HTTP::Methods, which is where the raw HTTP request is being formed.

To use it:


use Net::HTTP::Methods::patch::log_request;

# now all your LWP HTTP requests are logged

use LWP::UserAgent;
my $ua = LWP::UserAgent->new;
my $response = $ua->get('...');

Sample usage and output (by using LWP via WWW::Mechanize; you can see how Google redirects to the country-specific domain here):


% LOG_SHOW_CATEGORY=1 TRACE=1 perl -MLog::Any::App \
-MNet::HTTP::Methods::patch::log_request -MWWW::Mechanize \
-e'$mech=WWW::Mechanize->new; $mech->get("http://www.google.com/")'
[cat Net.HTTP.Methods.patch.log_request][23] HTTP request (142 bytes):
GET / HTTP/1.1
TE: deflate,gzip;q=0.3
Connection: TE, close
Accept-Encoding: gzip
Host: www.google.com
User-Agent: WWW-Mechanize/1.71

[cat Net.HTTP.Methods.patch.log_request][70] HTTP request (144 bytes):
GET / HTTP/1.1
TE: deflate,gzip;q=0.3
Connection: TE, close
Accept-Encoding: gzip
Host: www.google.co.id
User-Agent: WWW-Mechanize/1.71


1 Comment

Leave a comment

About Steven Haryanto

user-pic A programmer (mostly Perl 5 nowadays). My CPAN ID: SHARYANTO. I'm sedusedan on perlmonks. My twitter is stevenharyanto (but I don't tweet much). Follow me on github: sharyanto.