File Coverage

blib/lib/Log/Dispatch/UDP.pm
Criterion Covered Total %
statement 36 36 100.0
branch 3 6 50.0
condition n/a
subroutine 10 10 100.0
pod 0 2 0.0
total 49 54 90.7


line stmt bran cond sub pod time code
1             package Log::Dispatch::UDP;
2              
3 3     3   8360370 use v5.8;
  3         3086  
4 3     3   84 use strict;
  3         48  
  3         224  
5 3     3   25 use warnings;
  3         45  
  3         834  
6 3     3   40 use parent 'Log::Dispatch::Output';
  3         23  
  3         1293  
7              
8 3     3   153851 use Carp qw(croak);
  3         7  
  3         313  
9 3     3   23 use IO::Socket::INET;
  3         8  
  3         129  
10 3     3   4268 use Socket 2.026 qw(SOCK_DGRAM);
  3         119  
  3         184  
11              
12 3     3   44 use namespace::clean;
  3         7  
  3         216  
13              
14             # ABSTRACT: Log messages to a remote UDP socket
15              
16             our $VERSION = '0.02';
17              
18             sub new {
19 3     3 0 82 my ( $class, %params ) = @_;
20              
21 3 50       19 my $host = $params{'host'} or croak 'host parameter required';
22 3 50       15 my $port = $params{'port'} or croak 'port parameter required';
23              
24 3         50 my $sock = IO::Socket::INET->new(
25             Proto => 'udp',
26             Type => SOCK_DGRAM,
27             PeerAddr => $host,
28             PeerPort => $port,
29             );
30              
31 3 50       1970 croak $! unless $sock;
32              
33 3         21 my $self = bless {
34             sock => $sock,
35             }, $class;
36              
37 3         36 $self->_basic_init(%params);
38              
39 3         548 return $self;
40             }
41              
42             sub log_message {
43 2     2 0 424 my ( $self, %params ) = @_;
44              
45 2         5 my $message = $params{'message'};
46 2         4 my $sock = $self->{'sock'};
47              
48 2         60 $sock->send($message, 0);
49              
50 2         349 return;
51             }
52              
53             1;
54              
55             __END__
56              
57             =pod
58              
59             =encoding UTF-8
60              
61             =for stopwords netcat
62              
63             =head1 NAME
64              
65             Log::Dispatch::UDP - Log messages to a remote UDP socket
66              
67             =head1 VERSION
68              
69             version 0.02
70              
71             =head1 SYNOPSIS
72              
73             use Log::Dispatch;
74              
75             my $log = Log::Dispatch->new(
76             outputs => [
77             [
78             'UDP'
79             host => $destination_host,
80             port => $destination_port,
81             min_level => 'info',
82             ],
83             ],
84             );
85              
86             $log->info('my message');
87              
88             =head1 DESCRIPTION
89              
90             This class can be used to write messages to a UDP socket
91             listening on some remote host. The datagrams themselves
92             contain only the messages (there's no real structure to them),
93             so you can easily listen in using netcat.
94              
95             =head1 SECURITY CONSIDERATIONS
96              
97             Log messages are not encrypted. Be wary of logging authentication
98             details such as usernames, passwords or session ids, financial
99             information such as credit cards, or other personally identifying
100             information over unsecured channels.
101              
102             =head1 SEE ALSO
103              
104             L<Log::Dispatch>
105              
106             =for Pod::Coverage new
107              
108             =for Pod::Coverage log_message
109              
110             =head1 SOURCE
111              
112             The development version is on github at L<https://github.com/robrwo/perl-Log-Dispatch-UDP>
113             and may be cloned from L<https://github.com/robrwo/perl-Log-Dispatch-UDP.git>
114              
115             =head1 SUPPORT
116              
117             Only the latest version of this module will be supported.
118              
119             This module requires Perl v5.8 or later.
120             Future releases may only support Perl versions released in the last ten (10) years.
121              
122             =head2 Reporting Bugs and Submitting Feature Requests
123              
124             Please report any bugs or feature requests on the bugtracker website
125             L<https://github.com/robrwo/perl-Log-Dispatch-UDP/issues>
126              
127             When submitting a bug or request, please include a test-file or a
128             patch to an existing test-file that illustrates the bug or desired
129             feature.
130              
131             If the bug you are reporting has security implications which make it inappropriate to send to a public issue tracker,
132             then see F<SECURITY.md> for instructions how to report security vulnerabilities.
133              
134             =head1 AUTHOR
135              
136             Rob Hoelz <rob@hoelz.ro>
137              
138             This module is currently maintained by Robert Rothenberg <perl@rhizomnic.com>.
139              
140             =head1 CONTRIBUTOR
141              
142             =for stopwords Robert Rothenberg
143              
144             Robert Rothenberg <perl@rhizomnic.com>
145              
146             =head1 COPYRIGHT AND LICENSE
147              
148             This software is copyright (c) 2012, 2026 by Rob Hoelz <rob@hoelz.ro>.
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