1 19 package org.apache.avalon.excalibur.logger.log4j; 20 21 import org.apache.avalon.framework.configuration.Configurable; 22 import org.apache.avalon.framework.configuration.Configuration; 23 import org.apache.avalon.framework.configuration.ConfigurationException; 24 import org.apache.avalon.framework.configuration.ConfigurationUtil; 25 import org.apache.avalon.framework.context.Context; 26 import org.apache.avalon.framework.context.ContextException; 27 import org.apache.avalon.framework.context.Contextualizable; 28 import org.apache.log4j.Hierarchy; 29 import org.apache.log4j.Level; 30 import org.apache.log4j.spi.RootCategory; 31 import org.w3c.dom.Document ; 32 import org.w3c.dom.Element ; 33 import org.w3c.dom.Node ; 34 import org.w3c.dom.NodeList ; 35 36 57 public class Log4JConfAdapter extends Log4JAdapter 58 implements Configurable, Contextualizable 59 { 60 private Context m_context; 61 62 63 66 public void contextualize(Context context) throws ContextException 67 { 68 m_context = context; 69 } 70 71 78 public Log4JConfAdapter() 79 { 80 83 super( new Hierarchy( new RootCategory( Level.ALL ) ) ); 84 } 85 86 89 public void configure( final Configuration configuration ) 90 throws ConfigurationException 91 { 92 final Element element = ConfigurationUtil.toElement( configuration ); 93 final Document document = element.getOwnerDocument(); 94 final Element newElement = document.createElement( "log4j:configuration" ); 95 final NodeList childNodes = element.getChildNodes(); 96 final int length = childNodes.getLength(); 97 for( int i = 0; i < length; i++ ) 98 { 99 final Node node = childNodes.item( i ); 100 final Node newNode = node.cloneNode( true ); 101 newElement.appendChild( newNode ); 102 } 103 104 document.appendChild( newElement ); 105 106 111 final Log4JConfigurator domConfigurator = new Log4JConfigurator( m_context ); 112 domConfigurator.doConfigure( newElement, m_hierarchy ); 113 } 114 } 115 | Popular Tags |