line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
## no critic (RequireUseStrict) |
2
|
|
|
|
|
|
|
package Log::Dispatch::UDP; |
3
|
|
|
|
|
|
|
{ |
4
|
|
|
|
|
|
|
$Log::Dispatch::UDP::VERSION = '0.01'; |
5
|
|
|
|
|
|
|
} |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
## use critic (RequireUseStrict) |
8
|
3
|
|
|
3
|
|
6877210
|
use strict; |
|
3
|
|
|
|
|
67
|
|
|
3
|
|
|
|
|
308
|
|
9
|
3
|
|
|
3
|
|
44
|
use warnings; |
|
3
|
|
|
|
|
31
|
|
|
3
|
|
|
|
|
532
|
|
10
|
3
|
|
|
3
|
|
3374
|
use parent 'Log::Dispatch::Output'; |
|
3
|
|
|
|
|
3040
|
|
|
3
|
|
|
|
|
93
|
|
11
|
|
|
|
|
|
|
|
12
|
3
|
|
|
3
|
|
26765
|
use Carp qw(croak); |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
456
|
|
13
|
3
|
|
|
3
|
|
31
|
use IO::Socket::INET; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
187
|
|
14
|
3
|
|
|
3
|
|
5731
|
use Socket qw(SOCK_DGRAM); |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
194
|
|
15
|
3
|
|
|
3
|
|
18
|
use Readonly; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
273
|
|
16
|
|
|
|
|
|
|
|
17
|
3
|
|
|
3
|
|
3525
|
use namespace::clean; |
|
3
|
|
|
|
|
71173
|
|
|
3
|
|
|
|
|
21
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
Readonly::Array my @VALID_PARAMS => qw(host port); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub new { |
22
|
3
|
|
|
3
|
1
|
132
|
my ( $class, %params ) = @_; |
23
|
|
|
|
|
|
|
|
24
|
3
|
50
|
|
|
|
42
|
my $host = $params{'host'} or croak 'host parameter required'; |
25
|
3
|
50
|
|
|
|
31
|
my $port = $params{'port'} or croak 'port parameter required'; |
26
|
|
|
|
|
|
|
|
27
|
3
|
|
|
|
|
57
|
my $sock = IO::Socket::INET->new( |
28
|
|
|
|
|
|
|
Proto => 'udp', |
29
|
|
|
|
|
|
|
Type => SOCK_DGRAM, |
30
|
|
|
|
|
|
|
PeerAddr => $host, |
31
|
|
|
|
|
|
|
PeerPort => $port, |
32
|
|
|
|
|
|
|
); |
33
|
|
|
|
|
|
|
|
34
|
3
|
50
|
|
|
|
1721
|
croak $! unless $sock; |
35
|
|
|
|
|
|
|
|
36
|
3
|
|
|
|
|
45
|
my $self = bless { |
37
|
|
|
|
|
|
|
sock => $sock, |
38
|
|
|
|
|
|
|
}, $class; |
39
|
|
|
|
|
|
|
|
40
|
3
|
|
|
|
|
40
|
$self->_basic_init(%params); |
41
|
|
|
|
|
|
|
|
42
|
3
|
|
|
|
|
610
|
return $self; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub log_message { |
46
|
2
|
|
|
2
|
1
|
372
|
my ( $self, %params ) = @_; |
47
|
|
|
|
|
|
|
|
48
|
2
|
|
|
|
|
6
|
my $message = $params{'message'}; |
49
|
2
|
|
|
|
|
5
|
my $sock = $self->{'sock'}; |
50
|
|
|
|
|
|
|
|
51
|
2
|
|
|
|
|
69
|
$sock->send($message, 0); |
52
|
|
|
|
|
|
|
|
53
|
2
|
|
|
|
|
284
|
return; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
1; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=pod |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head1 NAME |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
Log::Dispatch::UDP - Log messages to a remote UDP socket |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head1 VERSION |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
version 0.01 |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head1 SYNOPSIS |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
use Log::Dispatch; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
my $log = Log::Dispatch->new( |
75
|
|
|
|
|
|
|
outputs => [ |
76
|
|
|
|
|
|
|
[ |
77
|
|
|
|
|
|
|
'UDP' |
78
|
|
|
|
|
|
|
host => $destination_host, |
79
|
|
|
|
|
|
|
port => $destination_port, |
80
|
|
|
|
|
|
|
min_level => 'info', |
81
|
|
|
|
|
|
|
], |
82
|
|
|
|
|
|
|
], |
83
|
|
|
|
|
|
|
); |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
$log->info('my message'); |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 DESCRIPTION |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
This class can be used to write messages to a UDP socket |
90
|
|
|
|
|
|
|
listening on some remote host. The datagrams themselves |
91
|
|
|
|
|
|
|
contain only the messages (there's no real structure to them), |
92
|
|
|
|
|
|
|
so you can easily listen in using netcat. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 SEE ALSO |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
L |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=begin comment |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=over |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=item new |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=item log_message |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=back |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=end comment |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 AUTHOR |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Rob Hoelz |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
This software is copyright (c) 2012 by Rob Hoelz. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
119
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head1 BUGS |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Please report any bugs or feature requests on the bugtracker website |
124
|
|
|
|
|
|
|
https://github.com/hoelzro/log-dispatch-udp/issues |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
When submitting a bug or request, please include a test-file or a |
127
|
|
|
|
|
|
|
patch to an existing test-file that illustrates the bug or desired |
128
|
|
|
|
|
|
|
feature. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=cut |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
__END__ |