File Coverage

blib/lib/Log/Log4perl/Appender/Stomp.pm
Criterion Covered Total %
statement 9 25 36.0
branch 0 6 0.0
condition 0 8 0.0
subroutine 3 6 50.0
pod 1 2 50.0
total 13 47 27.6


line stmt bran cond sub pod time code
1             package Log::Log4perl::Appender::Stomp;
2             our $VERSION = '1.000';
3              
4             # ABSTRACT: Log messages via STOMP
5              
6 1     1   26416 use warnings;
  1         3  
  1         40  
7 1     1   5 use strict;
  1         2  
  1         38  
8              
9 1     1   998 use Net::Stomp;
  1         14761  
  1         11  
10              
11             our @ISA = qw(Log::Log4perl::Appender);
12              
13             sub new {
14 0     0 1   my ($class, %options) = @_;
15              
16 0   0       my $self = {
      0        
      0        
      0        
17             'name' => $options{'name'} || 'unknown',
18             'hostname' => $options{'hostname'} || 'localhost',
19             'port' => $options{'port'} || 61613,
20             'topic_name' => $options{'topic_name'} || 'log',
21             'connection' => undef,
22             %options
23             };
24              
25 0           bless($self, $class);
26              
27 0           return $self;
28             }
29              
30             sub log { ## no critic
31 0     0 0   my ($self, %params) = @_;
32              
33 0           my $stomp = $self->{'connection'};
34              
35 0 0         unless ($stomp) {
36              
37 0           $stomp = Net::Stomp->new(
38             {
39             'hostname' => $self->{'hostname'},
40             'port' => $self->{'port'}
41             }
42             );
43              
44 0 0         unless ($stomp->connect({ 'login' => 'noauth', 'passcode' => 'supportyet' })) {
45 0           die('Connection to ', $self->{'hostname'}, ':', $self->{'port'}, " failed: $!");
46             }
47              
48 0           $self->{'connection'} = $stomp;
49             }
50              
51 0           return $stomp->send(
52             {
53             'destination' => sprintf('/topic/%s', $self->{'topic_name'}),
54             'body' => $params{'message'}
55             }
56             );
57             }
58              
59             sub DESTROY {
60 0     0     my ($self) = @_;
61              
62 0 0         if ($self->{'connection'}) {
63 0           $self->{'connection'}->disconnect();
64             }
65              
66 0           return;
67             }
68              
69             1;
70              
71              
72              
73             =pod
74              
75             =head1 NAME
76              
77             Log::Log4perl::Appender::Stomp - Log messages via STOMP
78              
79             =head1 VERSION
80              
81             version 1.000
82              
83             =head1 SYNOPSIS
84              
85             use Log::Log4perl;
86              
87             # Default options are in $conf
88             my $conf = qq(
89             log4perl.category = WARN, STOMP
90              
91             log4perl.appender.STOMP = Log::Log4perl::Appender::Stomp
92             log4perl.appender.STOMP.hostname = localhost
93             log4perl.appender.STOMP.port = 61613
94             log4perl.appender.STOMP.topic_name = log
95             log4perl.appender.STOMP.layout = PatternLayout
96             log4perl.appender.STOMP.layout.ConversionPattern = %d %-5p %m%n
97             );
98              
99             Log::Log4perl::init(\$conf);
100              
101             Log::Log4perl->get_logger("blah")->debug("...");
102              
103             =head1 DESCRIPTION
104              
105             This allows you to send log messages via the Streaming Text Orientated Messaging
106             Protocol to a message broker that supports STOMP, such as Apache's ActiveMQ.
107              
108             This makes use of topics in ActiveMQ so that multiple consumers can receive the
109             log messages from multiple producers. It takes a similar approach as syslog
110             does but uses ActiveMQ to do the message handling.
111              
112             =head1 CONFIGURATION AND ENVIRONMENT
113              
114             You can change:
115              
116             =over
117              
118             =item * hostname
119              
120             =item * port
121              
122             =item * topic_name
123              
124             =back
125              
126             In the Log::Log4perl configuration.
127              
128             =over
129              
130             =item L
131              
132             =item L
133              
134             =item ActiveMQ L
135              
136             =back
137              
138             =head1 SUPPORT
139              
140             You can find documentation for this module with the perldoc command.
141              
142             perldoc Log::Log4perl::Appender::Stomp
143              
144             You can also look for information at:
145              
146             =over
147              
148             =item * RT: CPAN's request tracker: L
149              
150             =item * AnnoCPAN: Annotated CPAN documentation: L
151              
152             =item * CPAN Ratings: L
153              
154             =item * Search CPAN: L
155              
156             =back
157              
158             =head1 AUTHOR
159              
160             Adam Flott
161              
162             =head1 COPYRIGHT AND LICENSE
163              
164             This software is copyright (c) 2010 by Adam Flott.
165              
166             This is free software; you can redistribute it and/or modify it under
167             the same terms as the Perl 5 programming language system itself.
168              
169             =cut
170              
171              
172             __END__