line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package BusyBird::Log; |
2
|
19
|
|
|
19
|
|
35074
|
use strict; |
|
19
|
|
|
|
|
24
|
|
|
19
|
|
|
|
|
674
|
|
3
|
19
|
|
|
19
|
|
80
|
use warnings; |
|
19
|
|
|
|
|
25
|
|
|
19
|
|
|
|
|
529
|
|
4
|
19
|
|
|
19
|
|
69
|
use Exporter qw(import); |
|
19
|
|
|
|
|
20
|
|
|
19
|
|
|
|
|
3443
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our @EXPORT_OK = qw(bblog); |
7
|
|
|
|
|
|
|
our $Logger = \&default_logger; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub default_logger { |
10
|
0
|
|
|
0
|
0
|
0
|
my ($level, $msg) = @_; |
11
|
0
|
|
|
|
|
0
|
my ($caller_package) = caller(1); |
12
|
0
|
|
|
|
|
0
|
my $output = "$caller_package: $level: $msg"; |
13
|
0
|
0
|
|
|
|
0
|
$output .= "\n" if $output !~ /[\n\r]$/; |
14
|
0
|
|
|
|
|
0
|
print STDERR $output; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub bblog { |
18
|
52
|
|
|
52
|
1
|
1675
|
my ($level, $msg) = @_; |
19
|
52
|
100
|
|
|
|
179
|
$Logger->($level, $msg) if defined $Logger; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
1; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=pod |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 NAME |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
BusyBird::Log - simple logging infrastructure for BusyBird |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head1 SYNOPSIS |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
use BusyBird::Log qw(bblog); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
bblog('error', 'Something bad happens'); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
{ |
38
|
|
|
|
|
|
|
my @logs = (); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
## Temporarily change the Logger |
41
|
|
|
|
|
|
|
local $BusyBird::Log::Logger = sub { |
42
|
|
|
|
|
|
|
my ($level, $msg) = @_; |
43
|
|
|
|
|
|
|
push(@logs, [$level, $msg]); |
44
|
|
|
|
|
|
|
}; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
bblog('info', 'This goes to @logs array.'); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head1 DESCRIPTION |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
L manages the logger singleton used in L. |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
This module is used by some of the L component modules to log warning/error messages. |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 EXPORTABLE FUNCTIONS |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
The following functions are exported only by request. |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head2 bblog($level, $msg) |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Logs the given message. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
C<$level> is a string of log level such as 'info', 'warn', 'error', 'critical' etc. |
66
|
|
|
|
|
|
|
C<$msg> is the log message body. |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
By default, it prints the log to STDERR. |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 PACKAGE VARIABLES |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head2 $BusyBird::Log::Logger = CODEREF($level, $msg) |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
A subroutine reference that is called when C is called. |
76
|
|
|
|
|
|
|
The subroutine is supposed to do the logging. |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
Setting this to C disables logging at all. |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 AUTHOR |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Toshio Ito C<< >> |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=cut |
85
|
|
|
|
|
|
|
|