Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*     */ package org.apache.log4j;
  /*     */ 
  /*     */ import java.io.FilterWriter;
  /*     */ import java.io.IOException;
  /*     */ import java.io.OutputStream;
  /*     */ import java.io.OutputStreamWriter;
  /*     */ import java.io.Writer;
  /*     */ import org.apache.log4j.helpers.LogLog;
  /*     */ import org.apache.log4j.helpers.QuietWriter;
 /*     */ import org.apache.log4j.spi.ErrorHandler;
 /*     */ import org.apache.log4j.spi.LoggingEvent;
 /*     */ 
 /*     */ public class WriterAppender extends AppenderSkeleton
 /*     */ {
 /*  54 */   protected boolean immediateFlush = true;
 /*     */   protected String encoding;
 /*     */   protected QuietWriter qw;
 /*     */ 
 /*     */   public WriterAppender()
 /*     */   {
 /*     */   }
 /*     */ 
 /*     */   public WriterAppender(Layout layoutOutputStream os)
 /*     */   {
 /*  82 */     this(layoutnew OutputStreamWriter(os));
 /*     */   }
 /*     */ 
 /*     */   public WriterAppender(Layout layoutWriter writer)
 /*     */   {
 /*  93 */     this. = layout;
 /*  94 */     setWriter(writer);
 /*     */   }
 /*     */ 
 /*     */   public void setImmediateFlush(boolean value)
 /*     */   {
 /* 113 */     this. = value;
 /*     */   }
 /*     */ 
 /*     */   public boolean getImmediateFlush()
 /*     */   {
 /* 121 */     return this.;
 /*     */   }
 /*     */ 
 /*     */   public void activateOptions()
 /*     */   {
 /*     */   }
 /*     */ 
 /*     */   public void append(LoggingEvent event)
 /*     */   {
 /* 156 */     if (!checkEntryConditions()) {
 /* 157 */       return;
 /*     */     }
 /* 159 */     subAppend(event);
 /*     */   }
 /*     */ 
 /*     */   protected boolean checkEntryConditions()
 /*     */   {
 /* 170 */     if (this.) {
 /* 171 */       LogLog.warn("Not allowed to write to a closed appender.");
 /* 172 */       return false;
 /*     */     }
 /*     */ 
 /* 175 */     if (this. == null) {
 /* 176 */       this..error("No output stream or file set for the appender named [" + this. + "].");
 /*     */ 
 /* 178 */       return false;
 /*     */     }
 /*     */ 
 /* 181 */     if (this. == null) {
 /* 182 */       this..error("No layout set for the appender named [" + this. + "].");
 /* 183 */       return false;
 /*     */     }
 /* 185 */     return true;
 /*     */   }
 /*     */ 
 /*     */   public synchronized void close()
 /*     */   {
 /* 200 */     if (this.)
 /* 201 */       return;
 /* 202 */     this. = true;
 /* 203 */     writeFooter();
 /* 204 */     reset();
 /*     */   }
 /*     */ 
 /*     */   protected void closeWriter()
 /*     */   {
 /* 211 */     if (this. != null)
 /*     */       try {
 /* 213 */         this..close();
 /*     */       }
 /*     */       catch (IOException e)
 /*     */       {
 /* 217 */         LogLog.error("Could not close " + this.e);
 /*     */       }
 /*     */   }
 /*     */ 
 /*     */   protected OutputStreamWriter createWriter(OutputStream os)
 /*     */   {
 /* 230 */     OutputStreamWriter retval = null;
/*     */ 
/* 232 */     String enc = getEncoding();
/* 233 */     if (enc != null) {
/*     */       try {
/* 235 */         retval = new OutputStreamWriter(osenc);
/*     */       } catch (IOException e) {
/* 237 */         LogLog.warn("Error initializing output writer.");
/* 238 */         LogLog.warn("Unsupported encoding?");
/*     */       }
/*     */     }
/* 241 */     if (retval == null) {
/* 242 */       retval = new OutputStreamWriter(os);
/*     */     }
/* 244 */     return retval;
/*     */   }
/*     */ 
/*     */   public String getEncoding() {
/* 248 */     return this.;
/*     */   }
/*     */ 
/*     */   public void setEncoding(String value) {
/* 252 */     this. = value;
/*     */   }
/*     */ 
/*     */   public synchronized void setErrorHandler(ErrorHandler eh)
/*     */   {
/* 262 */     if (eh == null) {
/* 263 */       LogLog.warn("You have tried to set a null error-handler.");
/*     */     } else {
/* 265 */       this. = eh;
/* 266 */       if (this. != null)
/* 267 */         this..setErrorHandler(eh);
/*     */     }
/*     */   }
/*     */ 
/*     */   public synchronized void setWriter(Writer writer)
/*     */   {
/* 285 */     reset();
/* 286 */     this. = new QuietWriter(writerthis.);
/*     */ 
/* 288 */     writeHeader();
/*     */   }
/*     */ 
/*     */   protected void subAppend(LoggingEvent event)
/*     */   {
/* 301 */     this..write(this..format(event));
/*     */ 
/* 303 */     if (this..ignoresThrowable()) {
/* 304 */       String[] s = event.getThrowableStrRep();
/* 305 */       if (s != null) {
/* 306 */         int len = s.length;
/* 307 */         for (int i = 0; i < leni++) {
/* 308 */           this..write(s[i]);
/* 309 */           this..write(.);
/*     */         }
/*     */       }
/*     */     }
/*     */ 
/* 314 */     if (this.)
/* 315 */       this..flush();
/*     */   }
/*     */ 
/*     */   public boolean requiresLayout()
/*     */   {
/* 327 */     return true;
/*     */   }
/*     */ 
/*     */   protected void reset()
/*     */   {
/* 337 */     closeWriter();
/* 338 */     this. = null;
/*     */   }
/*     */ 
/*     */   protected void writeFooter()
/*     */   {
/* 348 */     if (this. != null) {
/* 349 */       String f = this..getFooter();
/* 350 */       if ((f != null) && (this. != null)) {
/* 351 */         this..write(f);
/* 352 */         this..flush();
/*     */       }
/*     */     }
/*     */   }
/*     */ 
/*     */   protected void writeHeader()
/*     */   {
/* 362 */     if (this. != null) {
/* 363 */       String h = this..getHeader();
/* 364 */       if ((h != null) && (this. != null))
/* 365 */         this..write(h);
/*     */     }
/*     */   }
/*     */ }
/* Location:           /home/mnovotny/projects/EMBEDDED_JBOSS_BETA3_COMMUNITY/embedded/output/lib/embedded-jboss/lib/thirdparty-all.jar
 * Qualified Name:     org.apache.log4j.WriterAppender
 * JD-Core Version:    0.6.0
 */
New to GrepCode? Check out our FAQ X