line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MozRepl::Log; |
2
|
|
|
|
|
|
|
|
3
|
12
|
|
|
12
|
|
63
|
use strict; |
|
12
|
|
|
|
|
24
|
|
|
12
|
|
|
|
|
487
|
|
4
|
12
|
|
|
12
|
|
65
|
use warnings; |
|
12
|
|
|
|
|
24
|
|
|
12
|
|
|
|
|
406
|
|
5
|
|
|
|
|
|
|
|
6
|
12
|
|
|
12
|
|
63
|
use base qw(Class::Accessor::Fast); |
|
12
|
|
|
|
|
22
|
|
|
12
|
|
|
|
|
2373
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw/levels/); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our %LEVELS = (); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
{ |
13
|
|
|
|
|
|
|
my @levels = qw/debug info warn error fatal/; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
for ( my $i = 0; $i < @levels; $i++ ) { |
16
|
|
|
|
|
|
|
my $name = $levels[$i]; |
17
|
|
|
|
|
|
|
my $level += $i; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
$LEVELS{$name} = $level; |
20
|
|
|
|
|
|
|
|
21
|
12
|
|
|
12
|
|
67
|
no strict 'refs'; |
|
12
|
|
|
|
|
22
|
|
|
12
|
|
|
|
|
6200
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
*{$name} = sub { |
24
|
22
|
|
|
22
|
|
2776
|
my $self = shift; |
25
|
|
|
|
|
|
|
|
26
|
22
|
50
|
|
|
|
70
|
if ( $self->enable($level) ) { |
27
|
22
|
|
|
|
|
116
|
$self->log( uc($name), @_ ); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
}; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
*{"is_$name"} = sub { |
32
|
22
|
|
|
22
|
|
266
|
my $self = shift; |
33
|
|
|
|
|
|
|
|
34
|
22
|
50
|
|
|
|
86
|
return ( $self->enable($level) ) ? 1 : 0; |
35
|
|
|
|
|
|
|
}; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head1 NAME |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
MozRepl::Log - MozRepl logging class |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 VERSION |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
version 0.01 |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=cut |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 SYNOPSIS |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
use MozRepl; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
my $repl = MozRepl->new; |
56
|
|
|
|
|
|
|
$repl->setup; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
$repl->log->debug("Look! someone on that wall!"); |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head1 METHODS |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head2 new(@levels) |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
Create instance. |
65
|
|
|
|
|
|
|
If you want to limit log levels, then specify only levels to want to use. |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
my $log = MozRepl::Log->new(qw/info error/); |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=cut |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub new { |
72
|
11
|
|
|
11
|
1
|
117
|
my ($class, @levels) = @_; |
73
|
11
|
|
|
|
|
90
|
my $self = $class->SUPER::new; |
74
|
|
|
|
|
|
|
|
75
|
55
|
|
|
|
|
159
|
$self->levels( |
76
|
|
|
|
|
|
|
[ @levels > 0 |
77
|
11
|
50
|
|
|
|
156
|
? grep { exists $LEVELS{$_} } map { lc($_) } @levels |
|
55
|
|
|
|
|
117
|
|
78
|
|
|
|
|
|
|
: keys %LEVELS |
79
|
|
|
|
|
|
|
] |
80
|
|
|
|
|
|
|
); |
81
|
|
|
|
|
|
|
|
82
|
11
|
|
|
|
|
180
|
return $self; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head2 enable($level) |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Return whether the specified level is enabled or not. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=cut |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub enable { |
92
|
44
|
|
|
44
|
1
|
90
|
my ( $self, $level ) = @_; |
93
|
44
|
50
|
|
|
|
66
|
( ( grep { $LEVELS{$_} == $level } @{ $self->levels } ) == 1 ) ? 1 : 0; |
|
220
|
|
|
|
|
1812
|
|
|
44
|
|
|
|
|
137
|
|
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head2 log($level, $messages) |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Logging messege as specified level. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=cut |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub log { |
103
|
22
|
|
|
22
|
1
|
41
|
my $self = shift; |
104
|
22
|
|
|
|
|
47
|
my $level = shift; |
105
|
22
|
|
|
|
|
49
|
my @messages = map { split(/\n/, $_) } @_; |
|
22
|
|
|
|
|
198
|
|
106
|
|
|
|
|
|
|
|
107
|
22
|
100
|
|
|
|
121
|
my $message = @messages > 1 ? join("\n", "", @messages) : shift @messages; |
108
|
|
|
|
|
|
|
|
109
|
22
|
|
|
|
|
3924
|
warn( sprintf( "[%s] %s\n", $level, $message ) ); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head2 debug($messeage) |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Logging message as debug level. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head2 info($messeage) |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
Logging message as info level. |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head2 warn($messeage) |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Logging message as warn level. |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head2 error($messeage) |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Logging message as error level. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head2 fatal($messeage) |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
Logging message as fatl level. |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head2 is_debug() |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
Return whether the debug level is enabled or not. |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head2 is_info() |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Return whether the info level is enabled or not. |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head2 is_warn() |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
Return whether the warn level is enabled or not. |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head2 is_error() |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Return whether the error level is enabled or not. |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head2 is_fatal() |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
Return whether the fatl level is enabled or not. |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head1 AUTHOR |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
Toru Yamaguchi, C<< >> |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head1 BUGS |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
Please report any bugs or feature requests to |
159
|
|
|
|
|
|
|
C, or through the web interface at |
160
|
|
|
|
|
|
|
L. I will be notified, and then you'll automatically be |
161
|
|
|
|
|
|
|
notified of progress on your bug as I make changes. |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
Copyright 2007 Toru Yamaguchi, All Rights Reserved. |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
168
|
|
|
|
|
|
|
under the same terms as Perl itself. |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=cut |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
1; # End of MozRepl::Log |