File Coverage

blib/lib/Log/Log4perl/Appender/SpreadSession.pm
Criterion Covered Total %
statement 10 12 83.3
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 14 16 87.5


line stmt bran cond sub pod time code
1             package Log::Log4perl::Appender::SpreadSession;
2             ##################################################
3              
4 1     1   23086 use 5.008008;
  1         5  
  1         45  
5 1     1   7 use strict;
  1         2  
  1         35  
6 1     1   5 use warnings;
  1         14  
  1         70  
7              
8             our $VERSION = '0.03';
9              
10             our @ISA = qw/ Log::Log4perl::Appender /;
11              
12 1     1   474 use Spread::Session;
  0            
  0            
13              
14             ##################################################
15             sub new {
16             ##################################################
17             my($class, %args) = @_;
18              
19             my $self = {
20             group => $args{group},
21             };
22              
23             # Create a new session
24             eval {
25             $self->{spread_session} = Spread::Session->new(
26             spread_name => $args{spread_name} ,
27             private_name => $args{private_name},
28             );
29             };
30             if ($@) {
31             warn "ERROR creating new $class: $@\n";
32             }
33              
34             bless $self, $class;
35              
36             return $self;
37             }
38              
39             ##################################################
40             sub log {
41             ##################################################
42             my ($self, %args) = @_;
43              
44             my $spread = $self->{spread_session};
45              
46             # do nothing if the Spread::Session object is missing
47             return unless $spread;
48              
49             # publish the message to the specified group
50             eval {
51             $spread->publish( $self->{group}, $args{message} );
52             };
53             # If you got an error warn about it and clear the
54             # Spread::Session object so we don't keep trying
55             if ($@) {
56             warn "ERROR logging to spread via ".ref($self).": $@\n";
57             $self->{spread_session} = undef;
58             }
59              
60             return;
61             }
62              
63             1;
64              
65             __END__