line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Log::Log4perl::Appender::Elasticsearch::Bulk; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
33844
|
use 5.006; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
53
|
|
4
|
2
|
|
|
2
|
|
6
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
41
|
|
5
|
2
|
|
|
2
|
|
18
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
57
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
7
|
use constant _INTERNAL_DEBUG => 0; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
96
|
|
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
7
|
use base 'Log::Log4perl::Appender::Elasticsearch'; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
623
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 NAME |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Log::Log4perl::Appender::Elasticsearch::Bulk |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 DESCRIPTION |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
This appender is based on L. It buffers the log entries and flush by certain buffer size or on destroy. |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 VERSION |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
Version 0.07 |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=cut |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
$Log::Log4perl::Appender::Elasticsearch::VERSION = '0.07'; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 OPTIONS |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=over 4 |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=item |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
buffer_size |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
the number of log entries in a bulk load. |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
default 50 |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=back |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
For further options see L |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=cut |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub new { |
46
|
1
|
|
|
1
|
1
|
1174
|
my ($class, %p) = @_; |
47
|
1
|
|
|
|
|
2
|
my $fc = delete($p{buffer_size}); |
48
|
|
|
|
|
|
|
|
49
|
1
|
|
|
|
|
7
|
my $self = $class->SUPER::new(%p); |
50
|
|
|
|
|
|
|
|
51
|
1
|
|
|
|
|
3
|
$self->{_buffer} = []; |
52
|
1
|
|
50
|
|
|
4
|
$self->{_buffer_size} = $fc || 50; |
53
|
|
|
|
|
|
|
|
54
|
1
|
|
|
|
|
4
|
return $self; |
55
|
|
|
|
|
|
|
} ## end sub new |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub _flush { |
58
|
1
|
|
|
1
|
|
1
|
my ($self) = @_; |
59
|
1
|
|
|
|
|
1
|
my $data = ""; |
60
|
1
|
|
|
|
|
2
|
my $buff = delete $self->{_buffer}; |
61
|
1
|
|
|
|
|
2
|
$self->{_buffer} = []; |
62
|
|
|
|
|
|
|
|
63
|
1
|
50
|
|
|
|
0
|
scalar(@{$buff}) || return; |
|
1
|
|
|
|
|
38
|
|
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
0
|
foreach (@{$buff}) { |
|
0
|
|
|
|
|
0
|
|
66
|
0
|
|
|
|
|
0
|
$data .= join $/, '{"create":{}}', $self->_to_json($_), ''; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
0
|
if (_INTERNAL_DEBUG) { |
70
|
|
|
|
|
|
|
require Data::Dumper; |
71
|
|
|
|
|
|
|
print Data::Dumper::Dumper($buff); |
72
|
|
|
|
|
|
|
print $data; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
0
|
$self->_send_request($data, '_bulk'); |
76
|
|
|
|
|
|
|
} ## end sub _flush |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub log { |
79
|
0
|
|
|
0
|
0
|
0
|
my ($self, %p) = @_; |
80
|
0
|
|
|
|
|
0
|
push @{ $self->{_buffer} }, $self->_prepare_body(%p); |
|
0
|
|
|
|
|
0
|
|
81
|
0
|
0
|
|
|
|
0
|
(scalar(@{ $self->{_buffer} }) == $self->{_buffer_size}) && $self->_flush(); |
|
0
|
|
|
|
|
0
|
|
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub DESTROY { |
85
|
1
|
|
|
1
|
|
418
|
my ($self) = @_; |
86
|
1
|
|
|
|
|
1
|
_INTERNAL_DEBUG && print "_flush on destroy\n"; |
87
|
1
|
|
|
|
|
3
|
$self->_flush(); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 AUTHOR |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
Alexei Pastuchov |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 REPOSITORY |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
L |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Copyright 2015 by Alexei Pastuchov Epalik at cpan.orgE. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
103
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=cut |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
1; # End of Log::Log4perl::Appender::Elasticsearch::Bulk |