donaldp 2002/10/31 17:34:50
Added: logger/src/java/org/apache/avalon/excalibur/logger
Log4JConfLoggerManager.java
logger/src/test/org/apache/avalon/excalibur/logger/test
Log4JConfTestCase.java
Removed: logger/src/java/org/apache/avalon/excalibur/logger
Log4jConfLoggerManager.java
logger/src/test/org/apache/avalon/excalibur/logger/test
Log4jConfTestCase.java
Log:
Renamed Log4jConf* to Log4JConf for consistencies sake and to make the build
actually work when Log4j is not present.
Submitted By: [EMAIL PROTECTED] (Corey O'Donovan)
PR: 14127
Revision Changes Path
1.1
jakarta-avalon-excalibur/logger/src/java/org/apache/avalon/excalibur/logger/Log4JConfLoggerManager.java
Index: Log4JConfLoggerManager.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.avalon.excalibur.logger;
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.configuration.ConfigurationUtil;
import org.apache.log4j.xml.DOMConfigurator;
import org.w3c.dom.Element;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.w3c.dom.Node;
/**
* A LoggerManager for Log4j that will configure the Log4j subsystem
* using specified configuration.
*
* @author <a href="mailto:Ole.Bulbuk at ebp.de">Ole Bulbuk</a>
* @version $Revision: 1.1 $ $Date: 2002/11/01 01:34:49 $
*/
public class Log4JConfLoggerManager
extends Log4JLoggerManager
implements Configurable
{
public void configure( final Configuration configuration )
throws ConfigurationException
{
final Element element = ConfigurationUtil.toElement( configuration );
final Document document = element.getOwnerDocument();
final Element newElement = document.createElement( "log4j:configuration" );
final NodeList childNodes = element.getChildNodes();
final int length = childNodes.getLength();
for( int i = 0; i < length; i++ )
{
final Node node = childNodes.item( i );
final Node newNode = node.cloneNode( true );
newElement.appendChild( newNode );
}
document.appendChild( newElement );
DOMConfigurator.configure( newElement );
}
}
1.1
jakarta-avalon-excalibur/logger/src/test/org/apache/avalon/excalibur/logger/test/Log4JConfTestCase.java
Index: Log4JConfTestCase.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.avalon.excalibur.logger.test;
import java.io.IOException;
import java.io.InputStream;
import junit.framework.TestCase;
import org.apache.avalon.excalibur.logger.Log4JConfLoggerManager;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
import org.apache.avalon.framework.container.ContainerUtil;
import org.apache.avalon.framework.logger.ConsoleLogger;
import org.apache.avalon.framework.logger.Logger;
import org.xml.sax.SAXException;
/**
*
* @author <a href="mailto:peter at apache.org">Peter Donald</a>
* @version $Revision: 1.1 $ $Date: 2002/11/01 01:34:50 $
*/
public class Log4JConfTestCase
extends TestCase
{
public Log4JConfTestCase( final String name )
{
super( name );
}
public void testWrite()
throws Exception
{
final Log4JConfLoggerManager manager = getManager( "log4j.xml" );
final Logger logger = manager.getDefaultLogger();
logger.warn( "Some random message" );
}
private Log4JConfLoggerManager getManager( final String resourceName )
throws Exception
{
final Configuration configuration = loadConfiguration( resourceName );
final Log4JConfLoggerManager manager = new Log4JConfLoggerManager();
ContainerUtil.enableLogging(manager, new ConsoleLogger());
ContainerUtil.configure( manager, configuration );
return manager;
}
private Configuration loadConfiguration( final String resourceName ) throws
SAXException, IOException, ConfigurationException
{
final InputStream resource = getResource( resourceName );
final DefaultConfigurationBuilder builder = new
DefaultConfigurationBuilder();
final Configuration configuration = builder.build( resource );
return configuration;
}
private InputStream getResource( final String resourceName )
{
final InputStream resource = getClass().getResourceAsStream( resourceName );
if( null == resource )
{
throw new NullPointerException( "resource" );
}
return resource;
}
}
--
To unsubscribe, e-mail: <mailto:avalon-cvs-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-cvs-help@;jakarta.apache.org>