line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MojoX::Log::Log4perl::Tiny; |
2
|
2
|
|
|
2
|
|
52727
|
use Mojo::Base -base; |
|
2
|
|
|
|
|
8834
|
|
|
2
|
|
|
|
|
9
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
our $VERSION = "0.01"; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
has 'logger'; |
7
|
|
|
|
|
|
|
has level => 'debug'; |
8
|
|
|
|
|
|
|
has max_history_size => 5; |
9
|
|
|
|
|
|
|
has history => sub { [] }; |
10
|
|
|
|
|
|
|
has format => sub { |
11
|
|
|
|
|
|
|
sub { |
12
|
|
|
|
|
|
|
'[' . localtime(shift) . '] [' . shift() . '] ' . join "\n", @_, ''; |
13
|
|
|
|
|
|
|
}; |
14
|
|
|
|
|
|
|
}; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my %LEVEL = ( |
17
|
|
|
|
|
|
|
debug => 1, |
18
|
|
|
|
|
|
|
info => 2, |
19
|
|
|
|
|
|
|
warn => 3, |
20
|
|
|
|
|
|
|
error => 4, |
21
|
|
|
|
|
|
|
fatal => 5, |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
{ |
25
|
2
|
|
|
2
|
|
503
|
no strict 'refs'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
352
|
|
26
|
|
|
|
|
|
|
for my $level (keys %LEVEL) { |
27
|
|
|
|
|
|
|
*$level = sub { |
28
|
8
|
|
|
8
|
|
4664
|
my $self = shift; |
29
|
8
|
100
|
|
|
|
14
|
return if not $self->is_level($level); |
30
|
|
|
|
|
|
|
|
31
|
7
|
|
|
|
|
55
|
my $history = $self->history; |
32
|
7
|
|
|
|
|
24
|
my $max = $self->max_history_size; |
33
|
|
|
|
|
|
|
|
34
|
7
|
|
|
|
|
33
|
push @$history, [ time, $level, @_ ]; |
35
|
7
|
|
|
|
|
21
|
shift @$history while @$history > $max; |
36
|
|
|
|
|
|
|
|
37
|
7
|
|
|
|
|
8
|
local $Log::Log4perl::caller_depth = 1; |
38
|
7
|
|
|
|
|
12
|
$self->logger->$level(@_); |
39
|
|
|
|
|
|
|
}; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub is_level { |
44
|
12
|
|
|
12
|
0
|
3937
|
my ($self, $level) = @_; |
45
|
12
|
|
66
|
|
|
53
|
$LEVEL{$level} >= $LEVEL{ $ENV{MOJO_LOG_LEVEL} || $self->level }; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
1; |
49
|
|
|
|
|
|
|
__END__ |