1 19 package org.apache.avalon.excalibur.logger; 20 21 import org.apache.avalon.excalibur.logger.log4j.Log4JConfigurator; 22 import org.apache.avalon.framework.configuration.Configurable; 23 import org.apache.avalon.framework.configuration.Configuration; 24 import org.apache.avalon.framework.configuration.ConfigurationException; 25 import org.apache.avalon.framework.configuration.ConfigurationUtil; 26 import org.apache.avalon.framework.context.Context; 27 import org.apache.avalon.framework.context.ContextException; 28 import org.apache.avalon.framework.context.Contextualizable; 29 import org.apache.log4j.LogManager; 30 import org.w3c.dom.Document ; 31 import org.w3c.dom.Element ; 32 import org.w3c.dom.Node ; 33 import org.w3c.dom.NodeList ; 34 35 42 public class Log4JConfLoggerManager 43 extends Log4JLoggerManager 44 implements Configurable, Contextualizable 45 { 46 private Context m_context; 47 48 49 52 public void contextualize(Context context) throws ContextException 53 { 54 m_context = context; 55 } 56 57 63 public static Log4JConfLoggerManager newInstance( final String prefix, 64 final String switchToCategory ) 65 { 66 return new Log4JConfLoggerManager( prefix, switchToCategory ); 67 } 68 69 public Log4JConfLoggerManager( final String prefix, final String switchToCategory ) 70 { 71 super( prefix, switchToCategory ); 72 } 73 74 public Log4JConfLoggerManager() 75 { 76 } 77 78 public void configure( final Configuration configuration ) 79 throws ConfigurationException 80 { 81 final Element element = ConfigurationUtil.toElement( configuration ); 82 final Document document = element.getOwnerDocument(); 83 final Element newElement = document.createElement( "log4j:configuration" ); 84 final NodeList childNodes = element.getChildNodes(); 85 final int length = childNodes.getLength(); 86 for( int i = 0; i < length; i++ ) 87 { 88 final Node node = childNodes.item( i ); 89 final Node newNode = node.cloneNode( true ); 90 newElement.appendChild( newNode ); 91 } 92 93 document.appendChild( newElement ); 94 95 Log4JConfigurator configurator = new Log4JConfigurator(m_context); 96 configurator.doConfigure( newElement, LogManager.getLoggerRepository()); 97 } 98 } 99 | Popular Tags |