File Coverage

blib/lib/Log/Dispatch/Message/Passing.pm
Criterion Covered Total %
statement 15 25 60.0
branch 0 4 0.0
condition 0 3 0.0
subroutine 5 7 71.4
pod 2 2 100.0
total 22 41 53.6


line stmt bran cond sub pod time code
1             package Log::Dispatch::Message::Passing;
2 2     2   47342 use base qw(Log::Dispatch::Output);
  2         5  
  2         2780  
3              
4 2     2   27548 use warnings;
  2         4  
  2         53  
5 2     2   11 use strict;
  2         15  
  2         62  
6 2     2   14 use Scalar::Util qw/ blessed /;
  2         3  
  2         197  
7 2     2   10 use Carp qw/ confess /;
  2         4  
  2         659  
8              
9             our $VERSION = '0.009';
10              
11             sub new {
12 0     0 1   my ($class, %arg) = @_;
13 0 0         confess("Need an 'output' argument") unless $arg{output};
14 0           my $output = $arg{output};
15 0 0 0       confess("output => $output must be an object which can ->consume")
16             unless blessed($output) && $output->can('consume');
17              
18 0           my $self = { output => $output };
19              
20 0           bless $self => $class;
21              
22             # this is our duty as a well-behaved Log::Dispatch plugin
23 0           $self->_basic_init(%arg);
24              
25 0           return $self;
26             }
27              
28             sub log_message {
29 0     0 1   my ($self, %p) = @_;
30 0           $self->{output}->consume({%p});
31             }
32              
33             =head1 NAME
34              
35             Log::Dispatch::Message::Passing - log events to Message::Passing
36              
37             =head1 SYNOPSIS
38              
39             In your application code:
40              
41             use Log::Dispatch;
42             use Log::Dispatch::Message::Passing;
43             use Message::Passing::Filter::Encoder::JSON;
44             use Message::Passing::Output::ZeroMQ;
45              
46             my $log = Log::Dispatch->new;
47              
48             $log->add(Log::Dispatch::Message::Passing->new(
49             name => 'myapp_aggregate_log',
50             min_level => 'debug',
51             output => Message::Passing::Filter::Encoder::JSON->new(
52             output_to => Message::Passing::Output::ZeroMQ->new(
53             connect => 'tcp://192.168.0.1:5558',
54             ),
55             ),
56             ));
57              
58             $log->warn($_) for qw/ foo bar baz /;
59              
60             On your central log server:
61              
62             message-pass --input ZeroMQ --input_options '{"socket_bind":"tcp://*:5558"}' \
63             --output File --output_options '{"filename":"myapp_aggregate.log"}'
64              
65             =head1 DESCRIPTION
66              
67             This provides a L log output system that sends logged events to
68             L.
69              
70             This allows you to use any of the Message::Passing outputs or filters
71             to process log events and send them across the network, and you can use
72             the toolkit to trivially construct a log aggregator.
73              
74             =head1 METHODS
75              
76             =head2 C<< new >>
77              
78             my $table_log = Log::Dispatch::Message::Passing->new(\%arg);
79              
80             This method constructs a new Log::Dispatch::Message::Passing output object.
81              
82             Required arguments are:
83              
84             output - a L L class.
85              
86             =head2 log_message
87              
88             This is the method which performs the actual logging, as detailed by
89             Log::Dispatch::Output.
90              
91             =cut
92              
93             =head1 SEE ALSO
94              
95             =over
96              
97             =item L
98              
99             The logging framework itself, allowing you to very simply build log
100             aggregation and processing servers.
101              
102             =item L
103              
104             The recommended network protocol for aggregating or transporting messages
105             across the network.
106              
107             Note that whilst this transport is recommended, it is B required by
108             this module, so you need to require (and depend on) L
109             separately.
110              
111             =item example/ directory
112              
113             Instantly runnable SYNOPSIS - plug into your application for easy log
114             aggregation.
115              
116             =back
117              
118             =head1 AUTHOR
119              
120             Tomas Doran (t0m) C<< >>
121              
122             =head1 SPONSORSHIP
123              
124             This module exists due to the wonderful people at Suretec Systems Ltd.
125             who sponsored it's development for its
126             VoIP division called SureVoIP for use with
127             the SureVoIP API -
128            
129              
130             =head1 COPYRIGHT
131              
132             Copyright Suretec Systems Ltd. 2012.
133              
134             =head1 LICENSE
135              
136             GNU Affero General Public License, Version 3
137              
138             If you feel this is too restrictive to be able to use this software,
139             please talk to us as we'd be willing to consider re-licensing under
140             less restrictive terms.
141              
142             =cut
143              
144             1;
145