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