1LWP::ConsoleLogger::EveUrsyewrheCroen(t3r)ibuted Perl DoLcWuPm:e:nCtoantsioolneLogger::Everywhere(3)
2
3
4
6 LWP::ConsoleLogger::Everywhere - LWP tracing everywhere
7
9 version 1.000001
10
12 use LWP::ConsoleLogger::Everywhere;
13
14 # somewhere deep down in the guts of your program
15 # there is some other module that creates an LWP::UserAgent
16 # and now it will tell you what it's up to
17
18 # somewhere else you can access and fine-tune those loggers
19 # individually:
20 my $loggers = LWP::ConsoleLogger::Everywhere->loggers;
21 $loggers->[0]->pretty(0);
22
23 # or all of them at once:
24 LWP::ConsoleLogger::Everywhere->set( pretty => 1);
25
26 # Redact sensitive data for all user agents
27 $ENV{LWPCL_REDACT_HEADERS} = 'Authorization,Foo,Bar';
28 $ENV{LWPCL_REDACT_PARAMS} = 'seekrit,password,credit_card';
29
30 # Or observe without changing your code
31 PERL5OPT="-MLWP::ConsoleLogger::Everywhere" carton install
32
33 perl -MLWP::ConsoleLogger::Everywhere my-script.pl
34
36 This module turns on LWP::ConsoleLogger::Easy debugging for every
37 LWP::UserAgent or Mojo::UserAgent based user agent anywhere in your
38 code. It doesn't matter what package or class it is in, or if you have
39 access to the object itself. All you need to do is "use" this module
40 anywhere in your code and it will work.
41
42 You can access and configure the loggers individually after they have
43 been created using the "loggers" class method. To change all of them at
44 once, use the "set" class method instead.
45
46 See
47 <https://www.olafalders.com/2021/12/01/observing-network-traffic-with-lwp-consolelogger-everywhere/>
48 for a practical example of how to use this module.
49
51 set( <setting> => <value> )
52 LWP::ConsoleLogger::Everywhere->set( dump_content => 0 );
53
54 This class method changes the given setting on all logger objects that
55 have been created so far. The first argument is the accessor name of
56 the setting you want to change, and the second argument is the new
57 value. This cannot be used to access current values. See "METHODS" in
58 LWP::ConsoleLogger#SUBROUTINES for what those settings are.
59
60 loggers
61 my $loggers = LWP::ConsoleLogger::Everywhere->loggers;
62 foreach my $logger ( @{ $loggers } ) {
63 # stop dumping headers
64 $logger->dump_headers( 0 );
65 }
66
67 This class method returns an array reference of all LWP::ConsoleLogger
68 objects that have been created so far, with the newest one last. You
69 can use them to fine-tune settings. If there is more than one user
70 agent in your application you will need to figure out which one is
71 which. Since this is for debugging only, trial and error is a good
72 strategy here.
73
75 LWPCL_LOGFILE
76 By default all data will be dumped to your console (as the name of this
77 module implies) using Log::Dispatch. You may change this behavior
78 though. The general approach is to do it from within your script, for
79 example like this:
80
81 use LWP::ConsoleLogger::Everywhere;
82 my $loggers = LWP::ConsoleLogger::Everywhere->loggers;
83 my $log_dispatch = Log::Dispatch->new(
84 outputs => [
85 [ 'File', min_level => 'debug', filename => 'log_file.txt' ],
86 [ 'Screen', min_level => 'debug' ],
87 ],
88 );
89 foreach my $logger ( @{ $loggers } ) {
90 $logger->logger($log_dispatch);
91 }
92
93 The second approach is simpler and is done via an environment variable,
94 for example you can run your script like this:
95
96 LWPCL_LOGFILE=foo.log perl -MLWP::ConsoleLogger::Everywhere foo.pl
97
98 this will be equivalent to the first approach with the following
99 Log::Dispatch logger:
100
101 my $log_dispatch = Log::Dispatch->new(
102 outputs => [ [ 'File', min_level => 'debug', filename => 'foo.log' ] ],
103 );
104
106 If there are several different user agents in your application, you
107 will get debug output from all of them. This could be quite cluttered.
108
109 Since LWP::ConsoleLogger::Everywhere does its magic during compile time
110 it will most likely catch every user agent in your application, unless
111 you "use LWP::ConsoleLogger::Everywhere" inside a file that gets loaded
112 at runtime. If the user agent you wanted to debug had already been
113 created at that time it cannot hook into the constructor any more.
114
115 LWP::ConsoleLogger::Everywhere works by catching new user agents
116 directly in LWP::UserAgent when they are created. That way all properly
117 implemented sub classes like WWW::Mechanize will go through it. But if
118 you encounter one that installs its own handlers into the user agent
119 after calling "new" in LWP::UserAgent that might overwrite the ones
120 LWP::ConsoleLogger installed.
121
122 LWP::ConsoleLogger::Everywhere will keep references to all user agents
123 that were ever created during for the lifetime of your application. If
124 you have a lot of lexical user agents that you recycle all the time
125 they will not actually go away and might consume memory.
126
128 For more information or if you want more detailed control see
129 LWP::ConsoleLogger.
130
132 Olaf Alders <olaf@wundercounter.com>
133
135 This software is Copyright (c) 2014 by MaxMind, Inc.
136
137 This is free software, licensed under:
138
139 The Artistic License 2.0 (GPL Compatible)
140
141
142
143perl v5.38.0 2023-07-20 LWP::ConsoleLogger::Everywhere(3)