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