You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by Edoardo Comar <ed...@capeclear.com> on 2001/11/05 15:24:40 UTC
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: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
RE: SocketAppender proposed change to avoid losing events
Posted by Edoardo Comar <ed...@capeclear.com>.
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: <ma...@jakarta.apache.org>
>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>