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.715'; |
20
|
55
|
|
|
55
|
|
28915
|
use Moo::Role; |
|
55
|
|
|
|
|
118
|
|
|
55
|
|
|
|
|
357
|
|
21
|
|
|
|
|
|
|
|
22
|
55
|
|
|
55
|
|
33126
|
use URI(); |
|
55
|
|
|
|
|
127142
|
|
|
55
|
|
|
|
|
1324
|
|
23
|
55
|
|
|
55
|
|
351
|
use Try::Tiny; |
|
55
|
|
|
|
|
133
|
|
|
55
|
|
|
|
|
3426
|
|
24
|
55
|
|
|
55
|
|
359
|
use Search::Elasticsearch::Util qw(new_error); |
|
55
|
|
|
|
|
118
|
|
|
55
|
|
|
|
|
486
|
|
25
|
55
|
|
|
55
|
|
15372
|
use namespace::clean; |
|
55
|
|
|
|
|
118
|
|
|
55
|
|
|
|
|
362
|
|
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
|
4681
|
my ( $self, $type, $msg, $vars ) = @_; |
58
|
16
|
|
|
|
|
91
|
my $error = new_error( $type, $msg, $vars ); |
59
|
16
|
|
|
|
|
324
|
$self->error($error); |
60
|
16
|
|
|
|
|
536
|
die $error; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
#=================================== |
64
|
|
|
|
|
|
|
sub throw_critical { |
65
|
|
|
|
|
|
|
#=================================== |
66
|
13
|
|
|
13
|
0
|
2214
|
my ( $self, $type, $msg, $vars ) = @_; |
67
|
13
|
|
|
|
|
51
|
my $error = new_error( $type, $msg, $vars ); |
68
|
13
|
|
|
|
|
282
|
$self->critical($error); |
69
|
13
|
|
|
|
|
429
|
die $error; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
#=================================== |
73
|
|
|
|
|
|
|
sub trace_request { |
74
|
|
|
|
|
|
|
#=================================== |
75
|
152
|
|
|
152
|
1
|
3722
|
my ( $self, $cxn, $params ) = @_; |
76
|
152
|
100
|
|
|
|
2932
|
return unless $self->is_trace; |
77
|
|
|
|
|
|
|
|
78
|
4
|
|
|
|
|
338
|
my $uri = URI->new( 'http://localhost:9200' . $params->{path} ); |
79
|
4
|
|
|
|
|
298
|
my %qs = ( %{ $params->{qs} }, pretty => "true" ); |
|
4
|
|
|
|
|
18
|
|
80
|
4
|
|
|
|
|
15
|
$uri->query_form( [ map { $_, $qs{$_} } sort keys %qs ] ); |
|
8
|
|
|
|
|
32
|
|
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
my $body |
83
|
|
|
|
|
|
|
= $params->{serialize} eq 'std' |
84
|
|
|
|
|
|
|
? $self->serializer->encode_pretty( $params->{body} ) |
85
|
4
|
100
|
|
|
|
379
|
: $params->{data}; |
86
|
|
|
|
|
|
|
|
87
|
4
|
|
|
|
|
8
|
my $content_type = ''; |
88
|
4
|
100
|
|
|
|
9
|
if ( defined $body ) { |
89
|
3
|
|
|
|
|
11
|
$body =~ s/'/\\u0027/g; |
90
|
3
|
|
|
|
|
8
|
$body = " -d '\n$body'\n"; |
91
|
3
|
|
|
|
|
7
|
$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
|
|
|
|
|
17
|
$uri, |
102
|
|
|
|
|
|
|
$body |
103
|
|
|
|
|
|
|
); |
104
|
|
|
|
|
|
|
|
105
|
4
|
|
|
|
|
118
|
$self->trace($msg); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
#=================================== |
109
|
|
|
|
|
|
|
sub trace_response { |
110
|
|
|
|
|
|
|
#=================================== |
111
|
116
|
|
|
116
|
1
|
1764
|
my ( $self, $cxn, $code, $response, $took ) = @_; |
112
|
116
|
100
|
|
|
|
1969
|
return unless $self->is_trace; |
113
|
|
|
|
|
|
|
|
114
|
2
|
|
100
|
|
|
220
|
my $body = $self->serializer->encode_pretty($response) || "\n"; |
115
|
2
|
|
|
|
|
13
|
$body =~ s/^/# /mg; |
116
|
|
|
|
|
|
|
|
117
|
2
|
|
|
|
|
12
|
my $msg = sprintf( |
118
|
|
|
|
|
|
|
"# Response: %s, Took: %d ms\n%s", # |
119
|
|
|
|
|
|
|
$code, $took * 1000, $body |
120
|
|
|
|
|
|
|
); |
121
|
|
|
|
|
|
|
|
122
|
2
|
|
|
|
|
44
|
$self->trace($msg); |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
#=================================== |
126
|
|
|
|
|
|
|
sub trace_error { |
127
|
|
|
|
|
|
|
#=================================== |
128
|
29
|
|
|
29
|
1
|
88
|
my ( $self, $cxn, $error ) = @_; |
129
|
29
|
100
|
|
|
|
645
|
return unless $self->is_trace; |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
my $body |
132
|
2
|
|
100
|
|
|
329
|
= $self->serializer->encode_pretty( $error->{vars}{body} || "\n" ); |
133
|
2
|
|
|
|
|
15
|
$body =~ s/^/# /mg; |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
my $msg |
136
|
2
|
|
|
|
|
14
|
= sprintf( "# ERROR: %s %s\n%s", ref($error), $error->{text}, $body ); |
137
|
|
|
|
|
|
|
|
138
|
2
|
|
|
|
|
50
|
$self->trace($msg); |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
#=================================== |
142
|
|
|
|
|
|
|
sub trace_comment { |
143
|
|
|
|
|
|
|
#=================================== |
144
|
1
|
|
|
1
|
1
|
334
|
my ( $self, $comment ) = @_; |
145
|
1
|
50
|
|
|
|
32
|
return unless $self->is_trace; |
146
|
1
|
|
|
|
|
209
|
$comment =~ s/^/# *** /mg; |
147
|
1
|
|
|
|
|
4
|
chomp $comment; |
148
|
1
|
|
|
|
|
22
|
$self->trace("$comment\n"); |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
#=================================== |
152
|
|
|
|
|
|
|
sub deprecation { |
153
|
|
|
|
|
|
|
#=================================== |
154
|
1
|
|
|
1
|
1
|
3
|
my $self = shift; |
155
|
|
|
|
|
|
|
|
156
|
1
|
|
|
|
|
26
|
$self->deprecate_handle->warnf( "[DEPRECATION] %s - In request: %s", @_ ); |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
1; |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
# ABSTRACT: Provides common functionality to Logger implementations |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
__END__ |