line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Licensed to Elasticsearch B.V. under one or more contributor |
2
|
|
|
|
|
|
|
# license agreements. See the NOTICE file distributed with |
3
|
|
|
|
|
|
|
# this work for additional information regarding copyright |
4
|
|
|
|
|
|
|
# ownership. Elasticsearch B.V. licenses this file to you under |
5
|
|
|
|
|
|
|
# the Apache License, Version 2.0 (the "License"); you may |
6
|
|
|
|
|
|
|
# not use this file except in compliance with the License. |
7
|
|
|
|
|
|
|
# You may obtain a copy of the License at |
8
|
|
|
|
|
|
|
# |
9
|
|
|
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0 |
10
|
|
|
|
|
|
|
# |
11
|
|
|
|
|
|
|
# Unless required by applicable law or agreed to in writing, |
12
|
|
|
|
|
|
|
# software distributed under the License is distributed on an |
13
|
|
|
|
|
|
|
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14
|
|
|
|
|
|
|
# KIND, either express or implied. See the License for the |
15
|
|
|
|
|
|
|
# specific language governing permissions and limitations |
16
|
|
|
|
|
|
|
# under the License. |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
package Search::Elasticsearch::Role::Logger; |
19
|
|
|
|
|
|
|
$Search::Elasticsearch::Role::Logger::VERSION = '7.717'; |
20
|
55
|
|
|
55
|
|
22815
|
use Moo::Role; |
|
55
|
|
|
|
|
104
|
|
|
55
|
|
|
|
|
297
|
|
21
|
|
|
|
|
|
|
|
22
|
55
|
|
|
55
|
|
25748
|
use URI(); |
|
55
|
|
|
|
|
96221
|
|
|
55
|
|
|
|
|
1029
|
|
23
|
55
|
|
|
55
|
|
300
|
use Try::Tiny; |
|
55
|
|
|
|
|
131
|
|
|
55
|
|
|
|
|
2881
|
|
24
|
55
|
|
|
55
|
|
328
|
use Search::Elasticsearch::Util qw(new_error); |
|
55
|
|
|
|
|
119
|
|
|
55
|
|
|
|
|
382
|
|
25
|
55
|
|
|
55
|
|
12674
|
use namespace::clean; |
|
55
|
|
|
|
|
96
|
|
|
55
|
|
|
|
|
323
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
has 'serializer' => ( is => 'ro', required => 1 ); |
28
|
|
|
|
|
|
|
has 'log_as' => ( is => 'ro', default => 'elasticsearch.event' ); |
29
|
|
|
|
|
|
|
has 'trace_as' => ( is => 'ro', default => 'elasticsearch.trace' ); |
30
|
|
|
|
|
|
|
has 'deprecate_as' => ( is => 'ro', default => 'elasticsearch.deprecation' ); |
31
|
|
|
|
|
|
|
has 'log_to' => ( is => 'ro' ); |
32
|
|
|
|
|
|
|
has 'trace_to' => ( is => 'ro' ); |
33
|
|
|
|
|
|
|
has 'deprecate_to' => ( is => 'ro' ); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
has 'trace_handle' => ( |
36
|
|
|
|
|
|
|
is => 'lazy', |
37
|
|
|
|
|
|
|
handles => [qw( trace tracef is_trace)] |
38
|
|
|
|
|
|
|
); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
has 'log_handle' => ( |
41
|
|
|
|
|
|
|
is => 'lazy', |
42
|
|
|
|
|
|
|
handles => [ qw( |
43
|
|
|
|
|
|
|
debug debugf is_debug |
44
|
|
|
|
|
|
|
info infof is_info |
45
|
|
|
|
|
|
|
warning warningf is_warning |
46
|
|
|
|
|
|
|
error errorf is_error |
47
|
|
|
|
|
|
|
critical criticalf is_critical |
48
|
|
|
|
|
|
|
) |
49
|
|
|
|
|
|
|
] |
50
|
|
|
|
|
|
|
); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
has 'deprecate_handle' => ( is => 'lazy' ); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
#=================================== |
55
|
|
|
|
|
|
|
sub throw_error { |
56
|
|
|
|
|
|
|
#=================================== |
57
|
16
|
|
|
16
|
0
|
3851
|
my ( $self, $type, $msg, $vars ) = @_; |
58
|
16
|
|
|
|
|
58
|
my $error = new_error( $type, $msg, $vars ); |
59
|
16
|
|
|
|
|
280
|
$self->error($error); |
60
|
16
|
|
|
|
|
430
|
die $error; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
#=================================== |
64
|
|
|
|
|
|
|
sub throw_critical { |
65
|
|
|
|
|
|
|
#=================================== |
66
|
13
|
|
|
13
|
0
|
1856
|
my ( $self, $type, $msg, $vars ) = @_; |
67
|
13
|
|
|
|
|
39
|
my $error = new_error( $type, $msg, $vars ); |
68
|
13
|
|
|
|
|
224
|
$self->critical($error); |
69
|
13
|
|
|
|
|
329
|
die $error; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
#=================================== |
73
|
|
|
|
|
|
|
sub trace_request { |
74
|
|
|
|
|
|
|
#=================================== |
75
|
152
|
|
|
152
|
1
|
3188
|
my ( $self, $cxn, $params ) = @_; |
76
|
152
|
100
|
|
|
|
2368
|
return unless $self->is_trace; |
77
|
|
|
|
|
|
|
|
78
|
4
|
|
|
|
|
272
|
my $uri = URI->new( 'http://localhost:9200' . $params->{path} ); |
79
|
4
|
|
|
|
|
276
|
my %qs = ( %{ $params->{qs} }, pretty => "true" ); |
|
4
|
|
|
|
|
14
|
|
80
|
4
|
|
|
|
|
14
|
$uri->query_form( [ map { $_, $qs{$_} } sort keys %qs ] ); |
|
8
|
|
|
|
|
28
|
|
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
my $body |
83
|
|
|
|
|
|
|
= $params->{serialize} eq 'std' |
84
|
|
|
|
|
|
|
? $self->serializer->encode_pretty( $params->{body} ) |
85
|
4
|
100
|
|
|
|
338
|
: $params->{data}; |
86
|
|
|
|
|
|
|
|
87
|
4
|
|
|
|
|
6
|
my $content_type = ''; |
88
|
4
|
100
|
|
|
|
7
|
if ( defined $body ) { |
89
|
3
|
|
|
|
|
10
|
$body =~ s/'/\\u0027/g; |
90
|
3
|
|
|
|
|
7
|
$body = " -d '\n$body'\n"; |
91
|
3
|
|
|
|
|
6
|
$content_type = '-H "Content-type: ' . $params->{mime_type} . '" '; |
92
|
|
|
|
|
|
|
} |
93
|
1
|
|
|
|
|
2
|
else { $body = "\n" } |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
my $msg = sprintf( |
96
|
|
|
|
|
|
|
"# Request to: %s\n" # |
97
|
|
|
|
|
|
|
. "curl %s-X%s '%s'%s", # |
98
|
|
|
|
|
|
|
$cxn->stringify, |
99
|
|
|
|
|
|
|
$content_type, |
100
|
|
|
|
|
|
|
$params->{method}, |
101
|
4
|
|
|
|
|
15
|
$uri, |
102
|
|
|
|
|
|
|
$body |
103
|
|
|
|
|
|
|
); |
104
|
|
|
|
|
|
|
|
105
|
4
|
|
|
|
|
102
|
$self->trace($msg); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
#=================================== |
109
|
|
|
|
|
|
|
sub trace_response { |
110
|
|
|
|
|
|
|
#=================================== |
111
|
116
|
|
|
116
|
1
|
1424
|
my ( $self, $cxn, $code, $response, $took ) = @_; |
112
|
116
|
100
|
|
|
|
1545
|
return unless $self->is_trace; |
113
|
|
|
|
|
|
|
|
114
|
2
|
|
100
|
|
|
168
|
my $body = $self->serializer->encode_pretty($response) || "\n"; |
115
|
2
|
|
|
|
|
9
|
$body =~ s/^/# /mg; |
116
|
|
|
|
|
|
|
|
117
|
2
|
|
|
|
|
10
|
my $msg = sprintf( |
118
|
|
|
|
|
|
|
"# Response: %s, Took: %d ms\n%s", # |
119
|
|
|
|
|
|
|
$code, $took * 1000, $body |
120
|
|
|
|
|
|
|
); |
121
|
|
|
|
|
|
|
|
122
|
2
|
|
|
|
|
31
|
$self->trace($msg); |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
#=================================== |
126
|
|
|
|
|
|
|
sub trace_error { |
127
|
|
|
|
|
|
|
#=================================== |
128
|
29
|
|
|
29
|
1
|
68
|
my ( $self, $cxn, $error ) = @_; |
129
|
29
|
100
|
|
|
|
446
|
return unless $self->is_trace; |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
my $body |
132
|
2
|
|
100
|
|
|
229
|
= $self->serializer->encode_pretty( $error->{vars}{body} || "\n" ); |
133
|
2
|
|
|
|
|
9
|
$body =~ s/^/# /mg; |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
my $msg |
136
|
2
|
|
|
|
|
9
|
= sprintf( "# ERROR: %s %s\n%s", ref($error), $error->{text}, $body ); |
137
|
|
|
|
|
|
|
|
138
|
2
|
|
|
|
|
33
|
$self->trace($msg); |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
#=================================== |
142
|
|
|
|
|
|
|
sub trace_comment { |
143
|
|
|
|
|
|
|
#=================================== |
144
|
1
|
|
|
1
|
1
|
327
|
my ( $self, $comment ) = @_; |
145
|
1
|
50
|
|
|
|
23
|
return unless $self->is_trace; |
146
|
1
|
|
|
|
|
172
|
$comment =~ s/^/# *** /mg; |
147
|
1
|
|
|
|
|
3
|
chomp $comment; |
148
|
1
|
|
|
|
|
17
|
$self->trace("$comment\n"); |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
#=================================== |
152
|
|
|
|
|
|
|
sub deprecation { |
153
|
|
|
|
|
|
|
#=================================== |
154
|
1
|
|
|
1
|
1
|
2
|
my $self = shift; |
155
|
|
|
|
|
|
|
|
156
|
1
|
|
|
|
|
20
|
$self->deprecate_handle->warnf( "[DEPRECATION] %s - In request: %s", @_ ); |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
1; |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
# ABSTRACT: Provides common functionality to Logger implementations |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
__END__ |