5 @EXPORT_OK = qw(level trace debug conns);
9 my @levels = qw(trace debug conns);
16 my $callpkg = caller(0);
27 Exporter::export($pack, $callpkg, @symbols);
35 if ($_ eq '+') { # all on
36 # switch on all levels
37 %current_level = map { $_ => 1 } @levels;
39 elsif ($_ eq '-') { # all off
42 elsif (/^([-+])(\w+)$/) {
43 $current_level{$2} = $1 eq '+';
46 Carp::croak("Illegal level format $_");
52 sub trace { _log(@_) if $current_level{'trace'}; }
53 sub debug { _log(@_) if $current_level{'debug'}; }
54 sub conns { _log(@_) if $current_level{'conns'}; }
60 $msg .= "\n" unless $msg =~ /\n$/; # ensure trailing "\n"
62 my($package,$filename,$line,$sub) = caller(2);
63 print STDERR "$sub: $msg";
73 LWP::Debug - debug routines for the libwww-perl library
77 use LWP::Debug qw(+ -conns);
79 # Used internally in the library
80 LWP::Debug::trace('send()');
81 LWP::Debug::debug('url ok');
82 LWP::Debug::conns("read $n bytes: $data");
86 LWP::Debug provides tracing facilities. The trace(), debug() and
87 conns() function are called within the library and they log
88 information at increasing levels of detail. Which level of detail is
89 actually printed is controlled with the C<level()> function.
91 The following functions are available:
97 The C<level()> function controls the level of detail being
98 logged. Passing '+' or '-' indicates full and no logging
99 respectively. Individual levels can switched on and of by passing the
100 name of the level with a '+' or '-' prepended. The levels are:
102 trace : trace function calls
103 debug : print debug messages
104 conns : show all data transfered over the connections
106 The LWP::Debug module provide a special import() method that allows
107 you to pass the level() arguments with initial use statement. If a
108 use argument start with '+' or '-' then it is passed to the level
109 function, else the name is exported as usual. The following two
110 statements are thus equivalent (if you ignore that the second pollutes
113 use LWP::Debug qw(+);
114 use LWP::Debug qw(level); level('+');
118 The C<trace()> function is used for tracing function
119 calls. The package and calling subroutine name is
120 printed along with the passed argument. This should
121 be called at the start of every major function.
125 The C<debug()> function is used for high-granularity
126 reporting of state in functions.
130 The C<conns()> function is used to show data being
131 transferred over the connections. This may generate