############################## # GS::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 GS::SpreadLog; use Spread qw(:SP :MESS :ERROR); # $log=new GS::SpreadLog("groupname"); sub new { my $pkg = shift; my $group = shift; $connect{'spread_name'} = "4803"; my ($mbox, $privategroup) = Spread::connect(\%connect); print STDERR "GS::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 "GS::SpreadLog SP_multicast: $sperrno \n"; } } # destructor sub DESTROY { my $self = shift; Spread::disconnect($self->{mbox}) } 1;