donaldp 2002/10/27 16:36:03
Modified: logger/src/java/org/apache/avalon/excalibur/logger
Log4JLoggerManager.java
Added: logger/src/java/org/apache/avalon/excalibur/logger
Log4jConfLoggerManager.java
logger/src/test/org/apache/avalon/excalibur/logger/test
Log4jConfTestCase.java log4j.xml
Log:
Added a Log4jConfLoggerManager class that will configure the Log4j system based on
supplied configuration. The configuration schema is the same as the Log4J format.
Originally Submitted By: Ole Bulbuk <[EMAIL PROTECTED]>
Revision Changes Path
1.8 +3 -3
jakarta-avalon-excalibur/logger/src/java/org/apache/avalon/excalibur/logger/Log4JLoggerManager.java
Index: Log4JLoggerManager.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/logger/src/java/org/apache/avalon/excalibur/logger/Log4JLoggerManager.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- Log4JLoggerManager.java 14 Oct 2002 12:48:19 -0000 1.7
+++ Log4JLoggerManager.java 28 Oct 2002 00:36:03 -0000 1.8
@@ -73,7 +73,7 @@
private final Map m_loggers = new HashMap();
/** The root logger to configure */
- private String m_prefix;
+ //private String m_prefix;
/** The hierarchy private to Log4JManager */
private LoggerRepository m_hierarchy;
@@ -140,7 +140,7 @@
final Logger defaultLogger,
final Logger logger )
{
- m_prefix = prefix;
+ //m_prefix = prefix;
m_hierarchy = hierarchy;
m_defaultLogger = defaultLogger;
m_logger = logger;
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/10/28 00:36:03 $
*/
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 );
newElement.appendChild( node.cloneNode( true ) );
}
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/10/28 00:36:03 $
*/
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;
}
}
1.1
jakarta-avalon-excalibur/logger/src/test/org/apache/avalon/excalibur/logger/test/log4j.xml
Index: log4j.xml
===================================================================
<log4j:configuration>
<appender name="FILE" class="org.apache.log4j.FileAppender">
<param name="File" value="System.out"/>
<param name="Append" value="false"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern"
value="%p - %m%n"/>
</layout>
</appender>
<root>
<priority value="debug"/>
<appender-ref ref="FILE"/>
</root>
</log4j:configuration>
--
To unsubscribe, e-mail: <mailto:avalon-cvs-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-cvs-help@;jakarta.apache.org>