line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Plack::Middleware::AccessLog::Structured::ZeroMQ; |
2
|
|
|
|
|
|
|
$Plack::Middleware::AccessLog::Structured::ZeroMQ::VERSION = '0.001001'; |
3
|
1
|
|
|
1
|
|
275710
|
use parent qw(Plack::Middleware::AccessLog::Structured); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
# ABSTRACT: Access log middleware which passes structured log messages into ZeroMQ |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
600025
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
4
|
use MRO::Compat; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
20
|
|
11
|
1
|
|
|
1
|
|
862
|
use Message::Passing::Output::ZeroMQ; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new { |
16
|
|
|
|
|
|
|
my ($class, $arg_ref) = @_; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my $self = $class->next::method($arg_ref); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
unless ($self->logger()) { |
21
|
|
|
|
|
|
|
my $output = Message::Passing::Output::ZeroMQ->new( |
22
|
|
|
|
|
|
|
connect => $self->{connect} || 'tcp://127.0.0.1:5552', |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
$self->logger(sub { |
25
|
|
|
|
|
|
|
$output->consume(@_); |
26
|
|
|
|
|
|
|
}); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
return $self; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
1; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
__END__ |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=pod |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=encoding UTF-8 |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head1 NAME |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
Plack::Middleware::AccessLog::Structured::ZeroMQ - Access log middleware which passes structured log messages into ZeroMQ |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head1 VERSION |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
version 0.001001 |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head1 SYNOPSIS |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
use Plack::Middleware::AccessLog::Structured::ZeroMQ; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
Plack::Middleware::AccessLog::Structured::ZeroMQ->wrap($app, |
55
|
|
|
|
|
|
|
connect => 'tcp://127.0.0.1:5552', |
56
|
|
|
|
|
|
|
callback => sub { |
57
|
|
|
|
|
|
|
my ($env, $message) = @_; |
58
|
|
|
|
|
|
|
$message->{foo} = 'bar'; |
59
|
|
|
|
|
|
|
return $message; |
60
|
|
|
|
|
|
|
}, |
61
|
|
|
|
|
|
|
extra_field => { |
62
|
|
|
|
|
|
|
'some.application.field' => 'log_field', |
63
|
|
|
|
|
|
|
'some.psgi-env.field' => 'another_log_field', |
64
|
|
|
|
|
|
|
}, |
65
|
|
|
|
|
|
|
); |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head1 DESCRIPTION |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
Plack::Middleware::AccessLog::Structured::ZeroMQ is a |
70
|
|
|
|
|
|
|
L<Plack::Middleware|Plack::Middleware> which sends structured, JSON-encoded log |
71
|
|
|
|
|
|
|
messages into a ZeroMQ message queue. It is a subclass of |
72
|
|
|
|
|
|
|
L<Plack::Middleware::AccessLog::Structured|Plack::Middleware::AccessLog::Structured> |
73
|
|
|
|
|
|
|
and thus uses its log messages. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 METHODS |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head2 new |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
Constructor, creates new instance. See also the base class |
80
|
|
|
|
|
|
|
L<Plack::Middleware::AccessLog::Structured|Plack::Middleware::AccessLog::Structured> |
81
|
|
|
|
|
|
|
for additional parameters. Please note that you should not pass the C<logger> |
82
|
|
|
|
|
|
|
parameter to Plack::Middleware::AccessLog::Structured::ZeroMQ as that would |
83
|
|
|
|
|
|
|
override the default of passing log messages into ZeroMQ. |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head3 Parameters |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
This method expects its parameters as a hash reference. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=over |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=item connect |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
The address of the ZeroMQ endpoint to send the data to. Defaults to |
94
|
|
|
|
|
|
|
C<tcp://127.0.0.1:5552>. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=back |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head3 Result |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
A fresh instance of the middleware. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 SEE ALSO |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=over |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=item * |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
L<Plack::Middleware|Plack::Middleware> |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=item * |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
L<Plack::Middleware::AccessLog::Structured|Plack::Middleware::AccessLog::Structured>, |
113
|
|
|
|
|
|
|
the base class for this middleware. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=item * |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
L<Message::Passing|Message::Passing>, especially |
118
|
|
|
|
|
|
|
L<Message::Passing::Output::ZeroMQ|Message::Passing::Output::ZeroMQ> which is |
119
|
|
|
|
|
|
|
used by this middleware. |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
In order to receive log messages with L<Message::Passing|Message::Passing>, one |
122
|
|
|
|
|
|
|
can use a command like the following: |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
message-pass --input ZeroMQ --input_options '{"socket_bind":"tcp://*:5552"}' \ |
125
|
|
|
|
|
|
|
--output STDOUT |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=item * |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
L<Message::Passing::Output::ElasticSearch|Message::Passing::Output::ElasticSearch> |
130
|
|
|
|
|
|
|
which can serve as an output for L<Message::Passing|Message::Passing> to store |
131
|
|
|
|
|
|
|
the log messages into ElasticSearch. |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
In order to pass log messages to ElasticSearch, a command like the following can |
134
|
|
|
|
|
|
|
be used: |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
message-pass --input ZeroMQ --input_options '{"socket_bind":"tcp://*:5552"}' \ |
137
|
|
|
|
|
|
|
--output ElasticSearch --output_options '{"elasticsearch_servers":["127.0.0.1:9200"]}' \ |
138
|
|
|
|
|
|
|
--encoder Null |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=back |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head1 AUTHOR |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
Manfred Stock <mstock@cpan.org> |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
This software is copyright (c) 2016 by Manfred Stock. |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
151
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=cut |