1 package org.oddjob.logging; 2 3 import org.apache.log4j.AppenderSkeleton; 4 import org.apache.log4j.Layout; 5 import org.apache.log4j.spi.LoggingEvent; 6 7 10 11 public class ArchiveAppender extends AppenderSkeleton { 12 13 private final LogArchiverCache logArchiver; 14 15 21 public ArchiveAppender(LogArchiverCache logArchiver, Layout layout) { 22 this.logArchiver = logArchiver; 23 this.layout = layout; 24 } 25 26 public void close() { 27 } 28 29 public void append(LoggingEvent event) { 30 String archive = event.getLoggerName(); 31 if (!logArchiver.hasArchive(archive)) { 32 archive = (String ) event.getMDC(Log4jArchiver.MDC); 33 } 34 if (!logArchiver.hasArchive(archive)) { 35 return; 36 } 37 StringBuffer text = new StringBuffer (); 38 text.append(this.layout.format(event)); 39 40 if (layout.ignoresThrowable()) { 41 String [] s = event.getThrowableStrRep(); 42 if (s != null) { 43 int len = s.length; 44 for (int i = 0; i < len; i++) { 45 text.append(s[i]); 46 text.append(Layout.LINE_SEP); 47 } 48 } 49 } 50 51 logArchiver.addEvent(archive, Log4jArchiver.convertLevel(event.getLevel()), text.toString()); 52 } 53 54 public boolean requiresLayout() { 55 return false; 56 } 57 } 58 | Popular Tags |