++ed by:
TSIBLEY AERO ABRAXXA

3 PAUSE users
1 non-PAUSE user.

Olaf Alders 🐫
and 4 contributors

NAME

LWP::ConsoleLogger::Easy - Easy LWP tracing and debugging

VERSION

version 0.000036

SYNOPSIS

    use LWP::ConsoleLogger::Easy qw( debug_ua );
    use WWW::Mechanize;

    my $mech = WWW::Mechanize->new;
    my $logger = debug_ua( $mech );
    $mech->get('https://google.com');

    # now watch the console for debugging output

    # ...
    # stop dumping headers
    $logger->dump_headers( 0 );

    # Redact sensitive data
    $ENV{LWPCL_REDACT_HEADERS} = 'Authorization,Foo,Bar';
    $ENV{LWPCL_REDACT_PARAMS} = 'seekrit,password,credit_card';

    my $quiet_logger = debug_ua( $mech, 1 );

    my $noisy_logger = debug_ua( $mech, 5 );

DESCRIPTION

This module gives you the easiest possible introduction to LWP::ConsoleLogger. It offers one wrapper around LWP::ConsoleLogger: debug_ua. This function allows you to get up and running quickly with just a couple of lines of code. It instantiates LWP logging and also returns a LWP::ConsoleLogger object, which you may then tweak to your heart's desire.

If you're able to install HTML::FormatText::Lynx then you'll get highly readable HTML to text conversions.

FUNCTIONS

debug_ua( $mech, $verbosity )

When called without a verbosity argument, this function turns on all logging. I'd suggest going with this to start with and then turning down the verbosity after that. This method returns an LWP::ConsoleLogger object, which you may tweak to your heart's desire.

    my $ua_logger = debug_ua( $mech );
    $ua_logger->content_pre_filter( sub {...} );
    $ua_logger->logger( Log::Dispatch->new(...) );

    $mech->get(...);

You can provide a verbosity level of 0 or more. (Currently 0 - 8 supported.) This will turn up the verbosity on your output gradually. A verbosity of 0 will display nothing. 8 will display all available outputs.

    # don't get too verbose
    my $ua_logger = debug_ua( $mech, 4 );

add_ua_handlers

This method sets up response and request handlers on your user agent. This is done for you automatically if you're using debug_ua.

ENVIRONMENT VARIABLES

LWPCL_REDACT_HEADERS

A comma-separated list of header values to redact from output.

    $ENV{LWPCL_REDACT_HEADERS} = 'Authorization,Foo,Bar';

Output will be something like:

    .----------------+------------------.
    | Request Header | Value            |
    +----------------+------------------+
    | Authorization  | [REDACTED]       |
    | Content-Length | 0                |
    | User-Agent     | libwww-perl/6.15 |
    '----------------+------------------'

Use at the command line.

    LWPCL_REDACT_HEADERS='Authorization,Foo,Bar' perl script.pl

LWPCL_REDACT_PARAMS

A comma-separated list of parameter values to redact from output.

    $ENV{LWPCL_REDACT_PARAMS} = 'credit_card,foo,bar';

Use at the command line.

    LWPCL_REDACT_PARAMS='credit_card,foo,bar' perl script.pl

    .-------------+------------.
    | Key         | Value      |
    +-------------+------------+
    | credit_card | [REDACTED] |
    '-------------+------------'

CAVEATS

Text formatting now defaults to attempting to use HTML::FormatText::Lynx to format HTML as text. If you do not have this installed, we'll fall back to using HTML::Restrict to remove any HTML tags which you have not specifically whitelisted.

If you have HTML::FormatText::Lynx installed, but you don't want to use it, override the default filter:

    my $logger = debug_ua( $mech );
    $logger->text_pre_filter( sub { return shift } );

EXAMPLES

Please see the "examples" folder in this distribution for more ideas on how to use this module.

AUTHOR

Olaf Alders <olaf@wundercounter.com>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2014-2017 by MaxMind, Inc.

This is free software, licensed under:

  The Artistic License 2.0 (GPL Compatible)