Listing 1 Log::SpreadLog package
##############################
# Log::SpreadLog.pm -- for sending messages to spread groups,
# in the belief that somewhere a spreadlogd will hear them
# and write them to a file.
# Connects to local spread socket at /tmp/4803
package Log::SpreadLog;
use Spread qw(:SP :MESS :ERROR);
# $log=new Log::SpreadLog("groupname");
sub new {
my $pkg = shift;
my $group = shift;
$connect{'spread_name'} = "4803";
$connect{'group_membership'} = 0;
my ($mbox, $privategroup) = Spread::connect(\%connect);
print STDERR "Log::SpreadLog SP_connect: $sperrno \n" unless (defined($mbox));
bless { group => $group, mbox => $mbox }, $pkg;
}
# $log->write("this is a log message");
sub write {
my $self = shift;
my $message = shift;
if (Spread::multicast($self->{mbox}, RELIABLE_MESS,
$self->{group},0,$message."\n") <1) {
print STDERR "Log::SpreadLog SP_multicast: $sperrno \n";
}
}
# destructor
sub DESTROY {
my $self = shift;
Spread::disconnect($self->{mbox})
}
1;
|