line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
945
|
use strictures 2; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
49
|
|
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Dancer2::Logger::Radis; |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
# ABSTRACT: Dancer2 logger engine for Log::Radis |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
195
|
use Moo 2; |
|
1
|
|
|
|
|
13
|
|
|
1
|
|
|
|
|
6
|
|
8
|
1
|
|
|
1
|
|
302
|
use Log::Radis 0.002; |
|
1
|
|
|
|
|
25
|
|
|
1
|
|
|
|
|
23
|
|
9
|
1
|
|
|
1
|
|
4
|
use Carp qw(croak); |
|
1
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
55
|
|
10
|
1
|
|
|
1
|
|
4
|
use FindBin qw($RealBin $RealScript); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
625
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my $BIN = "$RealBin/$RealScript"; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
with 'Dancer2::Core::Role::Logger'; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our $VERSION = '0.002'; # VERSION |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
has server => ( |
21
|
|
|
|
|
|
|
is => 'ro', |
22
|
|
|
|
|
|
|
default => 'localhost:6379', |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
has reconnect => ( |
27
|
|
|
|
|
|
|
is => 'ro', |
28
|
|
|
|
|
|
|
default => 5, |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
has every => ( |
33
|
|
|
|
|
|
|
is => 'ro', |
34
|
|
|
|
|
|
|
default => 1, |
35
|
|
|
|
|
|
|
); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
has queue => ( |
39
|
|
|
|
|
|
|
is => 'ro', |
40
|
|
|
|
|
|
|
default => 'graylog-radis:queue', |
41
|
|
|
|
|
|
|
); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
has __mock => ( |
45
|
|
|
|
|
|
|
is => 'ro', |
46
|
|
|
|
|
|
|
); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
has _radis => ( |
49
|
|
|
|
|
|
|
is => 'lazy', |
50
|
|
|
|
|
|
|
builder => sub |
51
|
|
|
|
|
|
|
{ |
52
|
1
|
|
|
1
|
|
325
|
my $self = shift; |
53
|
1
|
|
|
|
|
18
|
my %opts = ( |
54
|
|
|
|
|
|
|
server => $self->server, |
55
|
|
|
|
|
|
|
reconnect => $self->reconnect, |
56
|
|
|
|
|
|
|
every => $self->every, |
57
|
|
|
|
|
|
|
queue => $self->queue, |
58
|
|
|
|
|
|
|
); |
59
|
1
|
50
|
|
|
|
10
|
if ($self->__mock) { |
60
|
1
|
|
|
|
|
4
|
$opts{redis} = $self->__mock; |
61
|
|
|
|
|
|
|
} |
62
|
1
|
|
|
|
|
11
|
Log::Radis->new(%opts); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
); |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub _dump |
67
|
|
|
|
|
|
|
{ |
68
|
3
|
|
|
3
|
|
15
|
Data::Dumper->new(\@_)->Terse(1)->Purity(1)->Indent(0)->Sortkeys(1)->Dump() |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub _serialize |
72
|
|
|
|
|
|
|
{ |
73
|
15
|
100
|
|
15
|
|
15
|
map { ref $_ ? _dump($_) : $_ } @_ |
|
15
|
|
|
|
|
44
|
|
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub log |
78
|
|
|
|
|
|
|
{ |
79
|
|
|
|
|
|
|
my $self = shift; |
80
|
|
|
|
|
|
|
my ($level, @args) = @_; |
81
|
|
|
|
|
|
|
my ($message, %extras) = map { _serialize($_) } @args; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
my %gelf = ( |
85
|
|
|
|
|
|
|
_source => $self->app_name, |
86
|
|
|
|
|
|
|
_pid => $$, |
87
|
|
|
|
|
|
|
_bin => $BIN, |
88
|
|
|
|
|
|
|
map {( '_dancer_'.lc($_) => $extras{$_} )} keys %extras |
89
|
|
|
|
|
|
|
); |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
if (my $request = $self->request) { |
92
|
|
|
|
|
|
|
$gelf{_http_id} = $request->id; |
93
|
|
|
|
|
|
|
$gelf{_http_user} = $request->user; |
94
|
|
|
|
|
|
|
$gelf{_http_client} = $request->address; |
95
|
|
|
|
|
|
|
$gelf{_http_method} = $request->method; |
96
|
|
|
|
|
|
|
$gelf{_http_path} = $request->path; |
97
|
|
|
|
|
|
|
$gelf{_http_proto} = $request->protocol; |
98
|
|
|
|
|
|
|
$gelf{_http_referer} = $request->header('referer'); |
99
|
|
|
|
|
|
|
$gelf{_http_useragent} = $request->header('user_agent'); |
100
|
|
|
|
|
|
|
if ($self->has_session) { |
101
|
|
|
|
|
|
|
$gelf{_session_id} = $request->session->id; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
$self->_radis->log($level, $message, %gelf); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
|
109
|
4
|
|
|
4
|
0
|
98964
|
sub core { @_ = (shift, 'core', @_); goto &log } |
|
4
|
|
|
|
|
73
|
|
110
|
1
|
|
|
1
|
0
|
5659
|
sub debug { @_ = (shift, 'debug', @_); goto &log } |
|
1
|
|
|
|
|
19
|
|
111
|
2
|
|
|
2
|
0
|
3169
|
sub info { @_ = (shift, 'info', @_); goto &log } |
|
2
|
|
|
|
|
44
|
|
112
|
1
|
|
|
1
|
0
|
440
|
sub warning { @_ = (shift, 'warning', @_); goto &log } |
|
1
|
|
|
|
|
16
|
|
113
|
1
|
|
|
1
|
0
|
521
|
sub error { @_ = (shift, 'error', @_); goto &log } |
|
1
|
|
|
|
|
16
|
|
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
1; |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
__END__ |