line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Log::Contextual::SimpleLogger; |
2
|
|
|
|
|
|
|
$Log::Contextual::SimpleLogger::VERSION = '0.008000'; |
3
|
|
|
|
|
|
|
# ABSTRACT: Super simple logger made for playing with Log::Contextual |
4
|
|
|
|
|
|
|
|
5
|
16
|
|
|
28
|
|
177071
|
use strict; |
|
16
|
|
|
|
|
98
|
|
|
16
|
|
|
|
|
627
|
|
6
|
16
|
|
|
28
|
|
120
|
use warnings; |
|
16
|
|
|
|
|
43
|
|
|
16
|
|
|
|
|
1081
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
{ |
9
|
|
|
|
|
|
|
for my $name (qw( trace debug info warn error fatal )) { |
10
|
|
|
|
|
|
|
|
11
|
16
|
|
|
28
|
|
169
|
no strict 'refs'; |
|
16
|
|
|
|
|
46
|
|
|
16
|
|
|
|
|
8355
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
*{$name} = sub { |
14
|
110
|
|
|
110
|
|
279
|
my $self = shift; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
$self->_log($name, @_) |
17
|
110
|
50
|
|
|
|
568
|
if ($self->{$name}); |
18
|
|
|
|
|
|
|
}; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
*{"is_$name"} = sub { |
21
|
135
|
|
|
135
|
|
371
|
my $self = shift; |
22
|
135
|
|
|
|
|
1208
|
return $self->{$name}; |
23
|
|
|
|
|
|
|
}; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub new { |
28
|
24
|
|
|
24
|
1
|
316425
|
my ($class, $args) = @_; |
29
|
24
|
|
|
|
|
98
|
my $self = bless {}, $class; |
30
|
|
|
|
|
|
|
|
31
|
24
|
|
|
|
|
67
|
$self->{$_} = 1 for @{$args->{levels}}; |
|
24
|
|
|
|
|
243
|
|
32
|
24
|
|
100
|
1
|
|
191
|
$self->{coderef} = $args->{coderef} || sub { print STDERR @_ }; |
|
1
|
|
|
|
|
38
|
|
33
|
|
|
|
|
|
|
|
34
|
24
|
100
|
|
|
|
121
|
if (my $upto = $args->{levels_upto}) { |
35
|
|
|
|
|
|
|
|
36
|
1
|
|
|
|
|
7
|
my @levels = (qw( trace debug info warn error fatal )); |
37
|
1
|
|
|
|
|
5
|
my $i = 0; |
38
|
1
|
|
|
|
|
4
|
for (@levels) { |
39
|
2
|
100
|
|
|
|
9
|
last if $upto eq $_; |
40
|
1
|
|
|
|
|
4
|
$i++ |
41
|
|
|
|
|
|
|
} |
42
|
1
|
|
|
|
|
5
|
for ($i .. $#levels) { |
43
|
5
|
|
|
|
|
17
|
$self->{$levels[$_]} = 1 |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
} |
47
|
24
|
|
|
|
|
456
|
return $self; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub _log { |
51
|
110
|
|
|
110
|
|
251
|
my $self = shift; |
52
|
110
|
|
|
|
|
242
|
my $level = shift; |
53
|
110
|
|
|
|
|
359
|
my $message = join("\n", @_); |
54
|
110
|
100
|
|
|
|
614
|
$message .= "\n" unless $message =~ /\n$/; |
55
|
110
|
|
|
|
|
717
|
$self->{coderef}->(sprintf("[%s] %s", $level, $message)); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
1; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
__END__ |