1 6 package org.logicalcobwebs.proxool.configuration; 7 8 import org.apache.avalon.framework.CascadingThrowable; 9 import org.apache.log.LogEvent; 10 import org.apache.log.Priority; 11 import org.apache.log.output.AbstractOutputTarget; 12 import org.apache.commons.logging.Log; 13 import org.apache.commons.logging.LogFactory; 14 15 24 public class LogKitTargetAdapter extends AbstractOutputTarget { 25 private boolean isOpen = true; 26 27 30 protected void doProcessEvent(LogEvent event) { 31 Throwable originalThrowable = event.getThrowable(); 37 Throwable nestedThrowable = null; 38 if (originalThrowable != null && originalThrowable instanceof CascadingThrowable) { 39 nestedThrowable = ((CascadingThrowable) originalThrowable).getCause(); 40 } 41 int priority = event.getPriority().getValue(); 42 if (originalThrowable != null && event.getPriority().isLower(Priority.WARN)) { 43 priority = Priority.WARN.getValue(); 44 } 45 Log logger = LogFactory.getLog(event.getCategory()); 46 if (Priority.DEBUG.getValue() == priority) { 47 if (logger.isDebugEnabled()) { 48 logger.debug(event.getMessage(), originalThrowable); 49 } 50 if (nestedThrowable != null) { 51 logger.debug("... caused by:", nestedThrowable); 52 } 53 } else if (Priority.INFO.getValue() == priority) { 54 if (logger.isInfoEnabled()) { 55 logger.info(event.getMessage(), originalThrowable); 56 } 57 if (nestedThrowable != null) { 58 logger.info("... caused by:", nestedThrowable); 59 } 60 } else if (Priority.WARN.getValue() == priority) { 61 logger.warn(event.getMessage(), originalThrowable); 62 if (nestedThrowable != null) { 63 logger.warn("... caused by:", nestedThrowable); 64 } 65 } else if (Priority.ERROR.getValue() == priority) { 66 logger.error(event.getMessage(), originalThrowable); 67 if (nestedThrowable != null) { 68 logger.error("... caused by:", nestedThrowable); 69 } 70 } else if (Priority.FATAL_ERROR.getValue() == priority) { 71 logger.fatal(event.getMessage(), originalThrowable); 72 if (nestedThrowable != null) { 73 logger.fatal("... caused by:", nestedThrowable); 74 } 75 } else { 76 logger.warn("Got log event of unknown priority: " + priority 77 + ". Message: " + event.getMessage(), originalThrowable); 78 } 79 } 80 81 84 protected boolean isOpen() { 85 return this.isOpen; 86 } 87 88 91 protected void open() { 92 this.isOpen = true; 93 } 94 95 98 public void close() { 99 this.isOpen = false; 100 } 101 102 } 103 104 | Popular Tags |