logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Edoardo Comar" <edoardo.co...@capeclear.com>
Subject RE: SocketAppender proposed change to avoid losing events
Date Mon, 05 Nov 2001 14:36:43 GMT
Actually,

What about this :
a generic Fallback Appender that wraps two appenders (set either in the
ctor or with a pair of setters) 
whose append(LoggingEvent) works as a decorator for the first - if it
fails then falls back to trying to append to the second.

Edo



> -----Original Message-----
> From: Edoardo Comar [mailto:edoardo.comar@capeclear.com] 
> Sent: 05 November 2001 14:25
> To: log4j-dev@jakarta.apache.org
> Subject: SocketAppender proposed change to avoid losing events
> 
> 
> Hi
> I need that if a SocketAppender encounters a problem during
>   public
>   void append(LoggingEvent event) {
> 
> I could at least emit the event to the local console rather 
> than losing the event.
> 
> 
> My suggestion is that the method
> 
>   public
>   void append(LoggingEvent event) {
>     if(event == null)
>       return;
> 
>     if(address==null) {
>       errorHandler.error("No remote host is set for 
> SocketAppender named \""+
> 			this.name+"\".");
>       return;
>     }
> 
>     if(oos != null) {
>       try {
> 	if(locationInfo) {
> 	   event.getLocationInformation();	
> 	} 
> 	oos.writeObject(event);
> 	//LogLog.debug("=========Flushing.");
> 	oos.flush();
> 	if(++counter >= RESET_FREQUENCY) {
> 	  counter = 0;
> 	  // Failing to reset the object output stream every now and
> 	  // then creates a serious memory leak.
> 	  //System.err.println("Doing oos.reset()");
> 	  oos.reset();
> 	}
>       }
>       catch(IOException e) {
> 	oos = null;
> 	LogLog.warn("Detected problem with connection: "+e);
> 	if(reconnectionDelay > 0) {
> 	  fireConnector();
> 	}
>       }
>     }
>   }
> 
> Could be changed as 
> 
>   public
>   void append(LoggingEvent event) {
>     if(event == null)
>       return;
> 
>     if(address==null) {
>       errorHandler.error("No remote host is set for 
> SocketAppender named \""+
> 			this.name+"\".");
>       return;
>     }
> 
>     if(oos != null) {
>       try {
> 	if(locationInfo) {
> 	   event.getLocationInformation();	
> 	} 
> 	oos.writeObject(event);
> 	//LogLog.debug("=========Flushing.");
> 	oos.flush();
> 	if(++counter >= RESET_FREQUENCY) {
> 	  counter = 0;
> 	  // Failing to reset the object output stream every now and
> 	  // then creates a serious memory leak.
> 	  //System.err.println("Doing oos.reset()");
> 	  oos.reset();
> 	}
>       }
>       catch(IOException e) {
> 	oos = null;
> 	//LogLog.warn("Detected problem with connection: "+e);
>       errorHandler.error("Detected problem with connection", 
> e, 0); //ADDED
> 	if(reconnectionDelay > 0) {
> 	  fireConnector();
> 	}
>       }
>     } else { //ADDED else block
>         errorHandler.error("No output stream available for 
> SocketAppender named \""+
>               this.name+"\".");
>         return;
>     }
>   }
> 
> 
> This way I could easily extend the SocketAppender which 
> Instantiates an error handler which could be checked for errors
> 
> and in SockeAppenderExtended
> append(LoggingEvent ) can be overridden 
> 1- synchronized
> 2 - calls super.append(event)
> 3 - then error handler is checked and if it has any errors  
> it is reset and the fallback appender is called to handle the event
> 
> 
> Regards,
> Edo
> 
> 
> --
> To unsubscribe, e-mail:   
> <mailto:log4j-dev-> unsubscribe@jakarta.apache.org>
> For 
> additional commands, 
> e-mail: <mailto:log4j-dev-help@jakarta.apache.org>
> 


--
To unsubscribe, e-mail:   <mailto:log4j-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:log4j-dev-help@jakarta.apache.org>


Mime
View raw message