1 19 package org.apache.avalon.excalibur.logger; 20 21 import org.apache.avalon.excalibur.logger.LoggerManager; 22 import org.apache.avalon.excalibur.logger.logkit.LogKitAdapter; 23 import org.apache.avalon.excalibur.logger.logkit.LogKitLoggerHelper; 24 import org.apache.avalon.excalibur.logger.logkit.LogKitConfHelper; 25 import org.apache.avalon.excalibur.logger.log4j.Log4JConfAdapter; 26 import org.apache.avalon.excalibur.logger.decorator.LogToSelfDecorator; 27 import org.apache.avalon.excalibur.logger.decorator.PrefixDecorator; 28 import org.apache.avalon.excalibur.logger.decorator.CachingDecorator; 29 import org.apache.avalon.excalibur.logger.util.LoggerManagerTee; 30 import org.apache.log.Hierarchy; 31 32 40 41 public class Facade 42 { 43 50 public static LoggerManager createLogKitConfigurable( 51 final String prefix, final String switchTo ) 52 { 53 final org.apache.log.Hierarchy hierarchy = new Hierarchy(); 54 55 final LoggerManager bare = new LogKitAdapter( hierarchy ); 56 final LoggerManager decorated = applyDecorators( bare, prefix, switchTo ); 57 final LoggerManagerTee tee = new LoggerManagerTee( decorated ); 58 59 tee.addTee( new LogKitLoggerHelper( hierarchy ) ); 60 tee.addTee( new LogKitConfHelper( hierarchy ) ); 61 tee.makeReadOnly(); 62 63 return tee; 64 } 65 66 71 public static LoggerManager createLog4JConfigurable( 72 final String prefix, final String switchTo ) 73 { 74 final LoggerManager bare = new Log4JConfAdapter(); 75 final LoggerManager decorated = applyDecorators( bare, prefix, switchTo ); 76 return decorated; 77 } 78 79 private static LoggerManager applyDecorators( LoggerManager target, 80 final String prefix, final String switchTo ) 81 { 82 if ( switchTo != null ) 83 { 84 target = new LogToSelfDecorator( target, switchTo ); 85 } 86 if ( prefix != null && prefix.length() > 0 ) 87 { 88 target = new PrefixDecorator( target, prefix ); 89 } 90 target = new CachingDecorator( target ); 91 return target; 92 } 93 } 94 | Popular Tags |