1 8 package org.apache.avalon.excalibur.logger; 9 10 import java.util.HashMap ; 11 import java.util.Map ; 12 import org.apache.avalon.framework.logger.Log4JLogger; 13 import org.apache.avalon.framework.logger.Logger; 14 import org.apache.log4j.Category; 15 import org.apache.log4j.Hierarchy; 16 17 26 public class Log4JLoggerManager 27 implements LoggerManager 28 { 29 30 final private Map m_loggers = new HashMap (); 31 32 33 private String m_prefix; 34 35 36 private Hierarchy m_hierarchy; 37 38 39 final private Logger m_defaultLogger; 40 41 44 public Log4JLoggerManager() 45 { 46 this( Category.getDefaultHierarchy() ); 47 } 48 49 52 public Log4JLoggerManager( final Hierarchy hierarchy ) 53 { 54 this( null, hierarchy ); 55 } 56 57 61 public Log4JLoggerManager( final String prefix ) 62 { 63 this( prefix, Category.getDefaultHierarchy() ); 64 } 65 66 70 public Log4JLoggerManager( final String prefix, final Hierarchy hierarchy ) 71 { 72 this( prefix, hierarchy, 73 new Log4JLogger( hierarchy.getInstance("") ) ); 74 } 75 76 80 public Log4JLoggerManager( final String prefix, final Hierarchy hierarchy, final Logger defaultLogger ) 81 { 82 m_prefix = prefix; 83 m_hierarchy = hierarchy; 84 m_defaultLogger = defaultLogger; 85 } 86 87 96 public final Logger getLoggerForCategory( final String categoryName ) 97 { 98 Logger logger = (Logger) m_loggers.get( categoryName ); 99 100 if( null != logger ) 101 { 102 if( m_defaultLogger.isDebugEnabled() ) 103 { 104 m_defaultLogger.debug( "Logger for category " + categoryName + " returned" ); 105 } 106 return logger; 107 } 108 109 if( m_defaultLogger.isDebugEnabled() ) 110 { 111 m_defaultLogger.debug( "Logger for category " + categoryName 112 + " not defined in configuration. New Logger created and returned" ); 113 } 114 115 logger = new Log4JLogger( m_hierarchy.getInstance( categoryName ) ); 116 m_loggers.put( categoryName, logger ); 117 return logger; 118 } 119 120 public final Logger getDefaultLogger() 121 { 122 return m_defaultLogger; 123 } 124 } 125 | Popular Tags |