From: <Dav...@ft...> - 2004-07-06 16:20:54
|
The current Log4Perl Socket appender code dies if the appender cannot initially connect to the target listener. The behavoir of the Log4j Socket appender is somewhat more forgiving. If the target listener is not available, one warning message is issued and a retry thread is started in the background. Until the listener becomes available, log events are silently discarded. When the listener becomes available, subsequent log events are successfully sent to the listener. I propose the current Log4perl Socket appender be changed to more closely mimic the Log4j logic. If the initial socket connection fails, a single warning should be issued. If any attempt to log an event to the socket appender fails, a reconnect should silently be tried. If the reconnect fails, the log event should be silently discarded. This behavior allows the socket appender to send messages when the listener is available, but discard them when the listener is down. Code snippets with changes from Socket.pm ################################################## sub new { ################################################## my($class, @options) = @_; my $self = { name => "unknown name", PeerAddr => "localhost", Proto => 'tcp', Timeout => 5, @options, }; bless $self, $class; unless($self->connect(@options)) { warn "Connect to $self->{PeerAddr}:$self->{PeerPort} failed: $!"; return $self ; } $self->{socket}->autoflush(1); return $self; } ################################################## sub log { ################################################## my($self, %params) = @_; { eval { $self->{socket}->send($params{message}); }; if($@) { # retry to connect to socket if send fails # fail silently # warn "Send to " . ref($self) . " failed ($@)"; if($self->connect(%$self)) { redo; } # fail silently # warn "Reconnect to $self->{PeerAddr}:$self->{PeerPort} " . "failed : $!"; return undef; } }; return 1; } |