1 16 package org.apache.avalon.excalibur.component; 17 18 import org.apache.avalon.excalibur.logger.LogKitManager; 19 import org.apache.avalon.excalibur.logger.LoggerManager; 20 import org.apache.avalon.framework.logger.LogKit2AvalonLoggerAdapter; 21 import org.apache.avalon.framework.logger.Logger; 22 import org.apache.log.Hierarchy; 23 import org.apache.log.LogTarget; 24 import org.apache.log.Priority; 25 26 27 35 class Logger2LogKitManager 36 implements LogKitManager 37 { 38 private final Hierarchy m_hierarchy = new Hierarchy(); 39 private final LoggerManager m_loggerManager; 40 41 public Logger2LogKitManager( final LoggerManager loggerManager ) 42 { 43 m_loggerManager = loggerManager; 44 final LogKit2AvalonLoggerAdapter target = 45 new LogKit2AvalonLoggerAdapter( loggerManager.getDefaultLogger() ); 46 m_hierarchy.setDefaultLogTarget( target ); 47 } 48 49 public org.apache.log.Logger getLogger( final String categoryName ) 50 { 51 final Logger logger = 52 m_loggerManager.getLoggerForCategory( categoryName ); 53 final org.apache.log.Logger logkitLogger = 54 getHierarchy().getLoggerFor( categoryName ); 55 final LogKit2AvalonLoggerAdapter target = 56 new LogKit2AvalonLoggerAdapter( logger ); 57 logkitLogger.setLogTargets( new LogTarget[ ] { target } ); 58 59 if ( logger.isDebugEnabled() ) 60 { 61 logkitLogger.setPriority( Priority.DEBUG ); 62 } 63 else if ( logger.isInfoEnabled() ) 64 { 65 logkitLogger.setPriority( Priority.INFO ); 66 } 67 else if ( logger.isWarnEnabled() ) 68 { 69 logkitLogger.setPriority( Priority.WARN ); 70 } 71 else if ( logger.isErrorEnabled() ) 72 { 73 logkitLogger.setPriority( Priority.ERROR ); 74 } 75 else if ( logger.isFatalErrorEnabled() ) 76 { 77 logkitLogger.setPriority( Priority.FATAL_ERROR ); 78 } 79 80 return logkitLogger; 81 } 82 83 public Hierarchy getHierarchy() 84 { 85 return m_hierarchy; 86 } 87 } 88 | Popular Tags |