line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojo::Log::JSON; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
961320
|
use Mojo::Base 'Mojo::Log'; |
|
3
|
|
|
|
|
14298
|
|
|
3
|
|
|
|
|
25
|
|
4
|
|
|
|
|
|
|
|
5
|
3
|
|
|
3
|
|
230242
|
use JSON; |
|
3
|
|
|
|
|
31112
|
|
|
3
|
|
|
|
|
25
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
has codec => sub { JSON->new->indent(0)->utf8->canonical }; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has default_fields => sub { |
12
|
|
|
|
|
|
|
{ datetime => sub { |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my ( $sec, $min, $hour, $mday, $mon, $year ) = gmtime(); |
15
|
|
|
|
|
|
|
sprintf( |
16
|
|
|
|
|
|
|
"%04d-%02d-%02d %02d:%02d:%02d", |
17
|
|
|
|
|
|
|
$year + 1900, |
18
|
|
|
|
|
|
|
$mon + 1, $mday, $hour, $min, $sec |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
}, |
21
|
|
|
|
|
|
|
}; |
22
|
|
|
|
|
|
|
}; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
has format => sub { |
25
|
|
|
|
|
|
|
my $self = shift; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
return sub { |
28
|
|
|
|
|
|
|
my ( $time, $level, @lines ) = @_; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
my %msg = ( |
31
|
|
|
|
|
|
|
( map { |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
my $value = $self->default_fields->{$_}; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
$_ => ref $value eq 'CODE' ? $value->() : $value; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
} keys %{ $self->default_fields } |
38
|
|
|
|
|
|
|
), |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
level => $level, |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
ref $lines[0] # data structure? |
43
|
|
|
|
|
|
|
? %{ $lines[0] } # multiple keys |
44
|
|
|
|
|
|
|
: ( message => join( "\n", @lines ) ), # single 'message' key |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
return $self->codec->encode( \%msg ) . "\n"; |
49
|
|
|
|
|
|
|
}; |
50
|
|
|
|
|
|
|
}; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
1; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
__END__ |