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.configuration.Configurable; 13 import org.apache.avalon.framework.configuration.Configuration; 14 import org.apache.avalon.framework.configuration.ConfigurationException; 15 import org.apache.avalon.framework.context.Context; 16 import org.apache.avalon.framework.context.ContextException; 17 import org.apache.avalon.framework.context.Contextualizable; 18 import org.apache.avalon.framework.logger.AbstractLogEnabled; 19 import org.apache.log.LogTarget; 20 21 29 public class DefaultLogTargetManager 30 extends AbstractLogEnabled 31 implements LogTargetManager, LogTargetFactoryManageable, Contextualizable, Configurable 32 { 33 34 final private Map m_targets = new HashMap (); 35 36 37 private Context m_context; 38 39 40 private LogTargetFactoryManager m_factory_manager; 41 42 49 public final LogTarget getLogTarget( final String id ) 50 { 51 final LogTarget logTarget = (LogTarget) m_targets.get( id ); 52 return logTarget; 53 } 54 55 61 public final void contextualize( final Context context ) 62 throws ContextException 63 { 64 m_context = context; 65 } 66 67 70 public final void setLogTargetFactoryManager( final LogTargetFactoryManager logTargetFactoryManager ) 71 { 72 m_factory_manager = logTargetFactoryManager; 73 } 74 75 81 public final void configure( final Configuration configuration ) 82 throws ConfigurationException 83 { 84 if( null == m_factory_manager) 85 { 86 throw new ConfigurationException( "LogTargetFactory not received" ); 87 } 88 89 final Configuration [] confs = configuration.getChildren(); 90 for( int i = 0; i < confs.length; i++ ) 91 { 92 final String targetName = confs[i].getName(); 93 final LogTargetFactory logTargetFactory = m_factory_manager.getLogTargetFactory( targetName ); 94 final LogTarget logTarget = logTargetFactory.createTarget( confs[i] ); 95 final String targetId = confs[i].getAttribute( "id" ); 96 if( getLogger().isDebugEnabled() ) 97 { 98 getLogger().debug( "added new LogTarget of id " + targetId ); 99 } 100 m_targets.put( targetId, logTarget ); 101 } 102 } 103 } 104 | Popular Tags |