line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Log::Log4perl::Appender::Spread; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
37283
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
42
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
39
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
6
|
use vars qw($VERSION); |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
59
|
|
7
|
|
|
|
|
|
|
$VERSION = 0.03; |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
1472
|
use Spread 3.17; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new { |
12
|
|
|
|
|
|
|
my($class, @options) = @_; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my $self = { |
15
|
|
|
|
|
|
|
@options |
16
|
|
|
|
|
|
|
}; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# set parameters |
19
|
|
|
|
|
|
|
$self->{SpreadGroup} = $self->{SpreadGroup} || 'LOG'; |
20
|
|
|
|
|
|
|
if ( !defined( $self->{SpreadMailbox} ) ) { |
21
|
|
|
|
|
|
|
# not called with an existing spread mailbox, so we need to join spread |
22
|
|
|
|
|
|
|
$self->{SpreadName} = $self->{SpreadName} || '4803'; |
23
|
|
|
|
|
|
|
$self->{SpreadPrivateName} = $self->{SpreadPrivateName} || 'log'; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
bless $self, $class; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
$self->spread_join(); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
return $self; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub spread_join { |
34
|
|
|
|
|
|
|
my($self) = @_; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
if ( !defined( $self->{SpreadMailbox} ) ) { |
37
|
|
|
|
|
|
|
# join spread, or die. |
38
|
|
|
|
|
|
|
($self->{mailbox}, $self->{private_group}) = |
39
|
|
|
|
|
|
|
Spread::connect( { |
40
|
|
|
|
|
|
|
spread_name => $self->{SpreadName}, |
41
|
|
|
|
|
|
|
private_name => $self->{SpreadPrivateName} |
42
|
|
|
|
|
|
|
} ); |
43
|
|
|
|
|
|
|
die("$sperrno") if ($sperrno); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
else { |
46
|
|
|
|
|
|
|
$self->{mailbox} = $self->{SpreadMailbox}; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
# now that connecting is done, join the logging group. |
49
|
|
|
|
|
|
|
die("Unable to join the spread group, $self->{SpreadGroup}") |
50
|
|
|
|
|
|
|
unless grep( Spread::join($self->{mailbox}, $_), $self->{SpreadGroup} ); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub spread_leave { |
54
|
|
|
|
|
|
|
my($self) = @_; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
if ( !$sperrno && defined($self->{mailbox}) ) { |
57
|
|
|
|
|
|
|
# the mailbox could be dead allready - so ignore errors, they dont make much sense anymore anyway |
58
|
|
|
|
|
|
|
Spread::leave($self->{mailbox}, $self->{SpreadGroup}); |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
if ( !defined($self->{SpreadMailbox}) ) { |
61
|
|
|
|
|
|
|
# dont disconnect unless you connected. |
62
|
|
|
|
|
|
|
Spread::disconnect($self->{mailbox}); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub log { |
69
|
|
|
|
|
|
|
my($self, %params) = @_; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# Send the message to the group joined. |
72
|
|
|
|
|
|
|
return Spread::multicast($self->{mailbox}, SAFE_MESS, $self->{SpreadGroup}, $params{level}, $params{message}); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub DESTROY { |
76
|
|
|
|
|
|
|
my($self) = @_; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
$self->spread_leave(); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
1; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
__END__ |