line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!perl |
2
|
|
|
|
|
|
|
#PODNAME: Raisin::Plugin::Logger |
3
|
|
|
|
|
|
|
#ABSTRACT: Logger plugin for Raisin. |
4
|
|
|
|
|
|
|
|
5
|
7
|
|
|
7
|
|
3064
|
use strict; |
|
7
|
|
|
|
|
14
|
|
|
7
|
|
|
|
|
221
|
|
6
|
7
|
|
|
7
|
|
34
|
use warnings; |
|
7
|
|
|
|
|
11
|
|
|
7
|
|
|
|
|
325
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
package Raisin::Plugin::Logger; |
9
|
|
|
|
|
|
|
$Raisin::Plugin::Logger::VERSION = '0.94'; |
10
|
7
|
|
|
7
|
|
36
|
use parent 'Raisin::Plugin'; |
|
7
|
|
|
|
|
15
|
|
|
7
|
|
|
|
|
35
|
|
11
|
|
|
|
|
|
|
|
12
|
7
|
|
|
7
|
|
300
|
use Carp qw(carp); |
|
7
|
|
|
|
|
13
|
|
|
7
|
|
|
|
|
318
|
|
13
|
7
|
|
|
7
|
|
1647
|
use Data::Dumper qw(Dumper); |
|
7
|
|
|
|
|
16362
|
|
|
7
|
|
|
|
|
441
|
|
14
|
7
|
|
|
7
|
|
3230
|
use POSIX qw(strftime); |
|
7
|
|
|
|
|
39831
|
|
|
7
|
|
|
|
|
105
|
|
15
|
7
|
|
|
7
|
|
8869
|
use Plack::Util; |
|
7
|
|
|
|
|
62
|
|
|
7
|
|
|
|
|
200
|
|
16
|
7
|
|
|
7
|
|
3024
|
use Time::HiRes qw(time); |
|
7
|
|
|
|
|
7470
|
|
|
7
|
|
|
|
|
29
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub build { |
19
|
6
|
|
|
6
|
1
|
20
|
my ($self, %args) = @_; |
20
|
|
|
|
|
|
|
|
21
|
6
|
100
|
|
|
|
22
|
my $logger = $args{fallback} ? 'Raisin::Logger' : 'Log::Dispatch'; |
22
|
|
|
|
|
|
|
|
23
|
6
|
|
|
|
|
9
|
my $obj; |
24
|
6
|
100
|
|
|
|
24
|
eval { $obj = Plack::Util::load_class($logger) } || do { |
|
6
|
|
|
|
|
16
|
|
25
|
1
|
|
|
|
|
328
|
carp 'Can\'t load `Log::Dispatch`. Fallback to `Raisin::Logger`!'; |
26
|
1
|
|
|
|
|
104
|
$obj = Plack::Util::load_class('Raisin::Logger'); |
27
|
|
|
|
|
|
|
}; |
28
|
|
|
|
|
|
|
|
29
|
6
|
|
|
|
|
75
|
$self->{logger} = $obj->new(%args); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
$self->register(log => sub { |
32
|
1
|
50
|
|
1
|
|
5
|
shift if ref($_[0]); |
|
|
|
|
1
|
|
|
|
33
|
1
|
|
|
|
|
2
|
$self->message(@_); |
34
|
6
|
|
|
|
|
63
|
}); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub message { |
38
|
1
|
|
|
1
|
0
|
3
|
my ($self, $level, $message, @args) = @_; |
39
|
|
|
|
|
|
|
|
40
|
1
|
|
|
|
|
3
|
my $t = time; |
41
|
1
|
|
|
|
|
76
|
my $time = strftime '%Y-%m-%dT%H:%M:%S', localtime $t; |
42
|
1
|
|
|
|
|
9
|
$time .= sprintf '.%03d', ($t - int($t)) * 1000; |
43
|
|
|
|
|
|
|
|
44
|
1
|
50
|
|
|
|
3
|
$message = ref($message) ? Dumper($message) : $message; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
$self->{logger}->log( |
47
|
1
|
|
|
|
|
6
|
level => $level, |
48
|
|
|
|
|
|
|
message => sprintf "$time $message\n", @args, |
49
|
|
|
|
|
|
|
); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
1; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
__END__ |