Return-Path: Delivered-To: apmail-jakarta-log4j-dev-archive@apache.org Received: (qmail 63015 invoked from network); 5 Nov 2001 14:36:50 -0000 Received: from unknown (HELO osaka.betaversion.org) (192.18.49.133) by daedalus.apache.org with SMTP; 5 Nov 2001 14:36:50 -0000 Received: (qmail 21164 invoked from network); 5 Nov 2001 14:39:13 -0000 Received: from nagoya.betaversion.org (192.18.49.131) by osaka.betaversion.org with SMTP; 5 Nov 2001 14:39:13 -0000 Received: (qmail 24883 invoked by uid 97); 5 Nov 2001 14:36:46 -0000 Delivered-To: qmlist-jakarta-archive-log4j-dev@jakarta.apache.org Received: (qmail 24868 invoked by uid 97); 5 Nov 2001 14:36:46 -0000 Mailing-List: contact log4j-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Log4J Developers List" Reply-To: "Log4J Developers List" Delivered-To: mailing list log4j-dev@jakarta.apache.org Received: (qmail 24856 invoked from network); 5 Nov 2001 14:36:45 -0000 From: "Edoardo Comar" To: "'Log4J Developers List'" Subject: RE: SocketAppender proposed change to avoid losing events Date: Mon, 5 Nov 2001 14:36:43 -0000 Message-ID: <003d01c16607$4aa92d90$1d02a8c0@EDOTOSH> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook, Build 10.0.2627 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 Importance: Normal In-Reply-To: <003401c16605$9b370b30$1d02a8c0@EDOTOSH> X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N 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: > unsubscribe@jakarta.apache.org> > For > additional commands, > e-mail: > -- To unsubscribe, e-mail: For additional commands, e-mail: