cvs commit: spice/components/loggerstore/xdocs configuration.xml
[email protected] Wed, 19 Nov 2003 12:22:44 -0600
| Newsgroups | gmane.comp.java.spice.cvs |
|---|---|
| Message-ID | <[email protected]> |
mauro 2003/11/19 12:22:44
Modified: components/loggerstore/src/test/META-INF/spice
loggerstore.properties
components/loggerstore project.xml
components/loggerstore/xdocs configuration.xml
Added: components/loggerstore/src/test/org/codehaus/spice/loggerstore
logkit-simple.xml MalformedLoggerStore.java
LoggerStoreTestCase.java logkit-excalibur.xml
MockLogKitLoggerStoreFactory.java log4j.properties
log4j.xml LoggerStoreFactoryTestCase.java
JDK14RawFormatter.java logging.properties
ConfiguratorTestCase.java AbstractTestCase.java
components/loggerstore/src/java/org/codehaus/spice/loggerstore/stores
Jdk14LoggerStore.java AbstractLoggerStore.java
Log4JLoggerStore.java ConsoleLoggerStore.java
LogKitLoggerStore.java
components/loggerstore/src/java/org/codehaus/spice/loggerstore/factories
SimpleLogKitLoggerStoreFactory.java
Jdk14LoggerStoreFactory.java
LogKitLoggerStoreFactory.java
InitialLoggerStoreFactory.java
DOMLog4JLoggerStoreFactory.java
ExcaliburLogKitLoggerStoreFactory.java
ConsoleLoggerStoreFactory.java
AbstractLoggerStoreFactory.java
PropertyLog4JLoggerStoreFactory.java
components/loggerstore/src/java/org/codehaus/spice/loggerstore
LoggerStore.java LoggerStoreFactory.java
Configurator.java
Removed: components/loggerstore/src/test/org/jcomponent/loggerstore
logkit-simple.xml MockLogKitLoggerStoreFactory.java
AbstractTestCase.java log4j.properties
JDK14RawFormatter.java MalformedLoggerStore.java
logging.properties log4j.xml
ConfiguratorTestCase.java logkit-excalibur.xml
LoggerStoreFactoryTestCase.java
LoggerStoreTestCase.java
components/loggerstore/src/java/org/jcomponent/loggerstore/factories
AbstractLoggerStoreFactory.java
SimpleLogKitLoggerStoreFactory.java
ExcaliburLogKitLoggerStoreFactory.java
LogKitLoggerStoreFactory.java
Jdk14LoggerStoreFactory.java
PropertyLog4JLoggerStoreFactory.java
ConsoleLoggerStoreFactory.java
InitialLoggerStoreFactory.java
DOMLog4JLoggerStoreFactory.java
components/loggerstore/src/java/org/jcomponent/loggerstore/stores
Jdk14LoggerStore.java AbstractLoggerStore.java
ConsoleLoggerStore.java LogKitLoggerStore.java
Log4JLoggerStore.java
components/loggerstore/src/java/org/jcomponent/loggerstore
Configurator.java LoggerStoreFactory.java
LoggerStore.java
Log:
Renamed org.jcomponent -> org.codehaus.spice
Revision Changes Path
1.1 spice/components/loggerstore/src/test/org/codehaus/spice/loggerstore/logkit-simple.xml
Index: logkit-simple.xml
===================================================================
<?xml version="1.0" encoding="UTF-8" ?>
<logkit xmlns:logkit="http://avalon.apache.org/logkit/">
<category name="" target="FILE1" priority="INFO" />
<log-target name="FILE1" location="logs/logkit-simple.log" format="%{message}\n" />
<category name="nejney" target="FILE2" priority="INFO" />
<log-target name="FILE2" location="logs/logkit-simple2.log" format="%{message}\n" />
</logkit>
1.1 spice/components/loggerstore/src/test/org/codehaus/spice/loggerstore/MalformedLoggerStore.java
Index: MalformedLoggerStore.java
===================================================================
/*
* Copyright (C) The Spice Group. All rights reserved.
*
* This software is published under the terms of the Spice
* Software License version 1.1, a copy of which has been included
* with this distribution in the LICENSE.txt file.
*/
package org.codehaus.spice.loggerstore;
import org.codehaus.spice.loggerstore.stores.AbstractLoggerStore;
import org.jcontainer.dna.Logger;
/**
*
* @author <a href="mailto:peter at realityforge.org">Peter Donald</a>
* @version $Revision: 1.1 $ $Date: 2003/11/19 18:22:43 $
*/
class MalformedLoggerStore
extends AbstractLoggerStore
{
protected Logger createLogger( String name )
{
return null;
}
public void close()
{
}
}
1.1 spice/components/loggerstore/src/test/org/codehaus/spice/loggerstore/LoggerStoreTestCase.java
Index: LoggerStoreTestCase.java
===================================================================
/*
* Copyright (C) The Spice Group. All rights reserved.
*
* This software is published under the terms of the Spice
* Software License version 1.1, a copy of which has been included
* with this distribution in the LICENSE.txt file.
*/
package org.codehaus.spice.loggerstore;
import java.util.Properties;
import org.apache.avalon.excalibur.logger.Log4JLoggerManager;
import org.apache.avalon.excalibur.logger.LogKitLoggerManager;
import org.apache.avalon.excalibur.logger.LoggerManager;
import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
import org.apache.avalon.framework.context.DefaultContext;
import org.apache.avalon.framework.logger.NullLogger;
import org.jcontainer.dna.impl.ConsoleLogger;
import org.codehaus.spice.loggerstore.stores.ConsoleLoggerStore;
import org.codehaus.spice.loggerstore.stores.Jdk14LoggerStore;
import org.codehaus.spice.loggerstore.stores.Log4JLoggerStore;
import org.codehaus.spice.loggerstore.stores.LogKitLoggerStore;
/**
* Test case for LoggerStore
*
* @author <a href="mailto:mauro.talevi at aquilonia.org">Mauro Talevi</a>
* @author <a href="mailto:peter at realityforge.org">Peter Donald</a>
*/
public class LoggerStoreTestCase
extends AbstractTestCase
{
public LoggerStoreTestCase( final String name )
{
super( name );
}
public void testNullRootLogger()
throws Exception
{
final LoggerStore store = new MalformedLoggerStore();
try
{
store.getLogger();
fail( "Expected to get an exception as no root logger is defined." );
}
catch( final Exception e )
{
}
}
// ConsoleLoggerStore tests
public void testConsoleLoggerStore()
throws Exception
{
final LoggerStore store =
new ConsoleLoggerStore( ConsoleLogger.LEVEL_DEBUG );
performConsoleTest( store, ConsoleLogger.LEVEL_DEBUG );
}
public void testConsoleLoggerStoreNoDebug()
throws Exception
{
final LoggerStore store =
new ConsoleLoggerStore( ConsoleLogger.LEVEL_DEBUG );
performConsoleTest( store, ConsoleLogger.LEVEL_NONE );
}
// LogKitLoggerStore tests
public void testLogKitExcaliburConfiguration()
throws Exception
{
final LoggerManager loggerManager = new LogKitLoggerManager();
final DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
final LoggerStore store =
new LogKitLoggerStore( loggerManager, null, null, builder.build( getResource( "logkit-excalibur.xml" ) ) );
runLoggerTest( "logkit-excalibur", store, ConsoleLogger.LEVEL_DEBUG );
}
public void testLogKitExcaliburConfigurationWithLogger()
throws Exception
{
final LoggerManager loggerManager = new LogKitLoggerManager();
final DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
final LoggerStore store =
new LogKitLoggerStore( loggerManager, new NullLogger(), null, builder.build( getResource( "logkit-excalibur.xml" ) ) );
runLoggerTest( "logkit-excalibur", store, ConsoleLogger.LEVEL_DEBUG );
}
public void testLogKitExcaliburConfigurationWithContext()
throws Exception
{
final LoggerManager loggerManager = new LogKitLoggerManager();
final DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
final LoggerStore store =
new LogKitLoggerStore( loggerManager, null, new DefaultContext(), builder.build( getResource( "logkit-excalibur.xml" ) ) );
runLoggerTest( "logkit-excalibur", store, ConsoleLogger.LEVEL_DEBUG );
}
public void testLogKitExcaliburConfigurationNoDebug()
throws Exception
{
final LoggerManager loggerManager = new LogKitLoggerManager();
final DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
final LoggerStore store =
new LogKitLoggerStore( loggerManager, null, null, builder.build( getResource( "logkit-excalibur.xml" ) ) );
runLoggerTest( "logkit-excalibur", store, ConsoleLogger.LEVEL_NONE );
}
public void testLogKitExcaliburConfigurationNoLog()
throws Exception
{
final LoggerManager loggerManager = new LogKitLoggerManager();
final DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
final LoggerStore store =
new LogKitLoggerStore( loggerManager, null, null, builder.build( getResource( "logkit-excalibur.xml" ) ) );
runLoggerTest( "logkit-excalibur", store );
}
public void testLogKitExcaliburConfigurationNoManager()
throws Exception
{
try
{
final LoggerStore store =
new LogKitLoggerStore( null, null, null, null);
fail( "Expected to get an exception as LoggerManager is null." );
}
catch( final Exception e )
{
}
}
public void testLogKitExcaliburConfigurationInvalidManager()
throws Exception
{
try
{
final LoggerManager loggerManager = new Log4JLoggerManager();
final DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
final LoggerStore store =
new LogKitLoggerStore( loggerManager, null, null, builder.build( getResource( "log4j.xml" ) ) );
fail( "Expected to get an exception as LoggerManager is invalid." );
}
catch( final Exception e )
{
}
}
// Log4JLoggerStore tests
public void testLog4JElementConfiguration()
throws Exception
{
final LoggerStore store =
new Log4JLoggerStore( buildElement( getResource( "log4j.xml" ),
new org.apache.log4j.xml.Log4jEntityResolver(), null ) );
runLoggerTest( "log4j-xml", store, ConsoleLogger.LEVEL_DEBUG );
}
public void testLog4JElementConfigurationNoDebug()
throws Exception
{
final LoggerStore store =
new Log4JLoggerStore( buildElement( getResource( "log4j.xml" ),
new org.apache.log4j.xml.Log4jEntityResolver(), null ) );
runLoggerTest( "log4j-xml", store, ConsoleLogger.LEVEL_NONE );
}
public void testLog4JElementConfigurationNoLog()
throws Exception
{
final LoggerStore store =
new Log4JLoggerStore( buildElement( getResource( "log4j.xml" ),
new org.apache.log4j.xml.Log4jEntityResolver(), null ) );
runLoggerTest( "log4j-xml", store );
}
public void testLog4JInputStreamConfiguration()
throws Exception
{
final LoggerStore store =
new Log4JLoggerStore( getResource( "log4j.xml" ) );
runLoggerTest( "log4j-xml", store, ConsoleLogger.LEVEL_DEBUG );
}
public void testLog4JInputStreamConfigurationNoDebug()
throws Exception
{
final LoggerStore store =
new Log4JLoggerStore( getResource( "log4j.xml" ) );
runLoggerTest( "log4j-xml", store, ConsoleLogger.LEVEL_NONE );
}
public void testLog4JInputStreamConfigurationNoLog()
throws Exception
{
final LoggerStore store =
new Log4JLoggerStore( getResource( "log4j.xml" ) );
runLoggerTest( "log4j-xml", store );
}
public void testLog4JPropertiesConfiguration()
throws Exception
{
final Properties properties = new Properties();
properties.load( getResource( "log4j.properties" ) );
final LoggerStore store =
new Log4JLoggerStore( properties );
runLoggerTest( "log4j-properties", store, ConsoleLogger.LEVEL_DEBUG );
}
public void testLog4JPropertiesConfigurationNoDebug()
throws Exception
{
final Properties properties = new Properties();
properties.load( getResource( "log4j.properties" ) );
final LoggerStore store =
new Log4JLoggerStore( properties );
runLoggerTest( "log4j-properties", store, ConsoleLogger.LEVEL_NONE );
}
public void testLog4JPropertiesConfigurationNoLog()
throws Exception
{
final Properties properties = new Properties();
properties.load( getResource( "log4j.properties" ) );
final LoggerStore store =
new Log4JLoggerStore( properties );
runLoggerTest( "log4j-properties", store );
}
// JDK14LoggerStore tests
public void testJDK14Configuration()
throws Exception
{
final LoggerStore store =
new Jdk14LoggerStore( getResource( "logging.properties" ) );
runLoggerTest( "jdk14", store, ConsoleLogger.LEVEL_DEBUG );
}
public void testJDK14ConfigurationNoDebug()
throws Exception
{
final LoggerStore store =
new Jdk14LoggerStore( getResource( "logging.properties" ) );
runLoggerTest( "jdk14", store, ConsoleLogger.LEVEL_NONE );
}
public void testJDK14ConfigurationNoLog()
throws Exception
{
final LoggerStore store =
new Jdk14LoggerStore( getResource( "logging.properties" ) );
runLoggerTest( "jdk14", store );
}
}
1.1 spice/components/loggerstore/src/test/org/codehaus/spice/loggerstore/logkit-excalibur.xml
Index: logkit-excalibur.xml
===================================================================
<?xml version="1.0" encoding="UTF-8" ?>
<logkit xmlns:logkit="http://avalon.apache.org/logkit/">
<factories>
<factory type="file" class="org.apache.avalon.excalibur.logger.factory.FileTargetFactory"/>
</factories>
<categories>
<category name="" log-level="INFO">
<log-target id-ref="FILE1"/>
</category>
<category name="nejney" log-level="INFO">
<log-target id-ref="FILE2"/>
</category>
</categories>
<targets>
<file id="FILE1">
<filename>logs/logkit-excalibur.log</filename>
<append>false</append>
<format type="extended">%{message}\n</format>
</file>
<file id="FILE2">
<filename>logs/logkit-excalibur2.log</filename>
<append>false</append>
<format type="extended">%{message}\n</format>
</file>
</targets>
</logkit>
1.1 spice/components/loggerstore/src/test/org/codehaus/spice/loggerstore/MockLogKitLoggerStoreFactory.java
Index: MockLogKitLoggerStoreFactory.java
===================================================================
/*
* Copyright (C) The Spice Group. All rights reserved.
*
* This software is published under the terms of the Spice
* Software License version 1.1, a copy of which has been included
* with this distribution in the LICENSE.txt file.
*/
package org.codehaus.spice.loggerstore;
import java.util.Map;
import org.codehaus.spice.loggerstore.factories.LogKitLoggerStoreFactory;
/**
* MockLogKitLoggerStoreFactory extends LogKitLoggerStoreFactory
* to allow testing of protected methods, not otherwise testable
*
* @author <a href="mailto:mauro.talevi at aquilonia.org">Mauro Talevi</a>
* @version $Revision: 1.1 $ $Date: 2003/11/19 18:22:43 $
*/
public class MockLogKitLoggerStoreFactory
extends LogKitLoggerStoreFactory
{
protected ClassLoader getClassLoader( final Map data )
{
return super.getClassLoader( data );
}
}
1.1 spice/components/loggerstore/src/test/org/codehaus/spice/loggerstore/log4j.properties
Index: log4j.properties
===================================================================
log4j.appender.FILE1=org.apache.log4j.FileAppender
log4j.appender.FILE1.File=logs/log4j-properties.log
log4j.appender.FILE1.Append=false
log4j.appender.FILE1.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE1.layout.ConversionPattern=%m%n
log4j.rootCategory=DEBUG, FILE1
log4j.appender.FILE2=org.apache.log4j.FileAppender
log4j.appender.FILE2.File=logs/log4j-properties2.log
log4j.appender.FILE2.Append=false
log4j.appender.FILE2.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE2.layout.ConversionPattern=%m%n
log4j.logger.nejney=DEBUG, FILE2
1.1 spice/components/loggerstore/src/test/org/codehaus/spice/loggerstore/log4j.xml
Index: log4j.xml
===================================================================
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration debug="true" xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="FILE1" class="org.apache.log4j.FileAppender">
<param name="File" value="logs/log4j-xml.log"/>
<param name="Append" value="false"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%m%n"/>
</layout>
</appender>
<appender name="FILE2" class="org.apache.log4j.FileAppender">
<param name="File" value="logs/log4j-xml2.log"/>
<param name="Append" value="false"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%m%n"/>
</layout>
</appender>
<category name="nejney">
<priority value="DEBUG"/>
<appender-ref ref="FILE2"/>
</category>
<root>
<priority value="DEBUG"/>
<appender-ref ref="FILE1"/>
</root>
</log4j:configuration>
1.1 spice/components/loggerstore/src/test/org/codehaus/spice/loggerstore/LoggerStoreFactoryTestCase.java
Index: LoggerStoreFactoryTestCase.java
===================================================================
/*
* Copyright (C) The Spice Group. All rights reserved.
*
* This software is published under the terms of the Spice
* Software License version 1.1, a copy of which has been included
* with this distribution in the LICENSE.txt file.
*/
package org.codehaus.spice.loggerstore;
import java.util.HashMap;
import java.util.Properties;
import org.apache.avalon.excalibur.logger.SimpleLogKitManager;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
import org.jcontainer.dna.Logger;
import org.jcontainer.dna.impl.ConsoleLogger;
import org.jcontainer.dna.impl.ContainerUtil;
import org.codehaus.spice.loggerstore.factories.ConsoleLoggerStoreFactory;
import org.codehaus.spice.loggerstore.factories.DOMLog4JLoggerStoreFactory;
import org.codehaus.spice.loggerstore.factories.ExcaliburLogKitLoggerStoreFactory;
import org.codehaus.spice.loggerstore.factories.InitialLoggerStoreFactory;
import org.codehaus.spice.loggerstore.factories.Jdk14LoggerStoreFactory;
import org.codehaus.spice.loggerstore.factories.LogKitLoggerStoreFactory;
import org.codehaus.spice.loggerstore.factories.PropertyLog4JLoggerStoreFactory;
import org.codehaus.spice.loggerstore.factories.SimpleLogKitLoggerStoreFactory;
import org.w3c.dom.Element;
/**
* Test case for LoggerStoreFactory
*
* @author <a href="mailto:mauro.talevi at aquilonia.org">Mauro Talevi</a>
* @author <a href="mailto:peter at realityforge.org">Peter Donald</a>
*/
public class LoggerStoreFactoryTestCase
extends AbstractTestCase
{
public LoggerStoreFactoryTestCase( final String name )
{
super( name );
}
// InitialLoggerStoreFactory tests
public void testInitialLoggerStoreFactoryFromConfigurerClassLoader()
throws Exception
{
Thread.currentThread().setContextClassLoader( null );
final HashMap config = new HashMap();
runFactoryTest( new InitialLoggerStoreFactory(),
ConsoleLogger.LEVEL_DEBUG,
config,
"log4j-properties" );
}
public void testInitialLoggerStoreFactoryUsingDefaults()
throws Exception
{
final HashMap config = new HashMap();
config.put( ClassLoader.class.getName(),
ClassLoader.getSystemClassLoader().getParent() );
final InitialLoggerStoreFactory factory = new InitialLoggerStoreFactory();
ContainerUtil.enableLogging( factory, new ConsoleLogger( ConsoleLogger.LEVEL_DEBUG ) );
try
{
factory.createLoggerStore( config );
fail( "Expected to not be able to create LoggerStoreFactory as no type was specified or on ClassPath" );
}
catch( final Exception e )
{
}
}
public void testInitialLoggerStoreFactoryUsingSpecifiedType()
throws Exception
{
final HashMap config = new HashMap();
config.put( InitialLoggerStoreFactory.INITIAL_FACTORY,
ConsoleLoggerStoreFactory.class.getName() );
final InitialLoggerStoreFactory factory = new InitialLoggerStoreFactory();
ContainerUtil.enableLogging( factory, new ConsoleLogger( ConsoleLogger.LEVEL_DEBUG ) );
final LoggerStore store = factory.createLoggerStore( config );
performConsoleTest( store, ConsoleLogger.LEVEL_DEBUG );
}
public void testInitialLoggerStoreFactoryWithInvalidType()
throws Exception
{
final HashMap config = new HashMap();
config.put( InitialLoggerStoreFactory.INITIAL_FACTORY, "Blah" );
final InitialLoggerStoreFactory factory = new InitialLoggerStoreFactory();
ContainerUtil.enableLogging( factory, new ConsoleLogger( ConsoleLogger.LEVEL_DEBUG ) );
try
{
factory.createLoggerStore( config );
fail( "Expected exception as invalid type specified" );
}
catch( final Exception e )
{
}
}
public void testInitialLoggerStoreFactoryFromSpecifiedClassLoader()
throws Exception
{
Thread.currentThread().setContextClassLoader( null );
final HashMap config = new HashMap();
config.put( ClassLoader.class.getName(),
InitialLoggerStoreFactory.class.getClassLoader() );
runFactoryTest( new InitialLoggerStoreFactory(),
ConsoleLogger.LEVEL_DEBUG,
config,
"log4j-properties" );
}
public void testInitialLoggerStoreFactoryFromContextClassLoader()
throws Exception
{
Thread.currentThread().setContextClassLoader( InitialLoggerStoreFactory.class.getClassLoader() );
final HashMap config = new HashMap();
runFactoryTest( new InitialLoggerStoreFactory(),
ConsoleLogger.LEVEL_DEBUG,
config,
"log4j-properties" );
}
// LogKitLoggerStoreFactory tests
public void testLogKitLoggerStoreFactoryInvalidInput()
throws Exception
{
runInvalidInputData( new LogKitLoggerStoreFactory() );
}
public void testLogKitLoggerStoreFactoryWithNullContextClassLoader()
throws Exception
{
final DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
final HashMap config = new HashMap();
config.put( Configuration.class.getName(),
builder.build( getResource( "logkit-excalibur.xml" ) ) );
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader( null );
final MockLogKitLoggerStoreFactory factory = new MockLogKitLoggerStoreFactory();
assertEquals("LogKit ClassLoader", factory.getClassLoader(config), LogKitLoggerStoreFactory.class.getClassLoader() );
Thread.currentThread().setContextClassLoader( contextClassLoader );
}
public void testLogKitLoggerStoreFactoryWithSpecifiedClassLoader()
throws Exception
{
final DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
final HashMap config = new HashMap();
config.put( Configuration.class.getName(),
builder.build( getResource( "logkit-excalibur.xml" ) ) );
config.put( ClassLoader.class.getName(),
LogKitLoggerStoreFactory.class.getClassLoader() );
runFactoryTest( new LogKitLoggerStoreFactory(),
ConsoleLogger.LEVEL_DEBUG,
config,
"logkit-excalibur" );
}
public void testLogKitLoggerStoreFactoryWithSpecifiedAvalonLogger()
throws Exception
{
final DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
final HashMap config = new HashMap();
config.put( Configuration.class.getName(),
builder.build( getResource( "logkit-excalibur.xml" ) ) );
config.put( org.apache.avalon.framework.logger.Logger.class.getName(),
new org.apache.avalon.framework.logger.ConsoleLogger() );
runFactoryTest( new LogKitLoggerStoreFactory(),
ConsoleLogger.LEVEL_INFO,
config,
"logkit-excalibur" );
}
public void testLogKitLoggerStoreFactoryWithConfigurationAndDefaultLoggerManager()
throws Exception
{
final DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
final HashMap config = new HashMap();
config.put( Configuration.class.getName(),
builder.build( getResource( "logkit-excalibur.xml" ) ) );
runFactoryTest( new LogKitLoggerStoreFactory(),
ConsoleLogger.LEVEL_INFO,
config,
"logkit-excalibur" );
}
public void testLogKitLoggerStoreFactoryWithConfigurationAndLoggerManager()
throws Exception
{
final DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
final HashMap config = new HashMap();
config.put( Configuration.class.getName(),
builder.build( getResource( "logkit-simple.xml" ) ) );
config.put( LogKitLoggerStoreFactory.LOGGER_MANAGER,
SimpleLogKitManager.class.getName() );
runFactoryTest( new LogKitLoggerStoreFactory(),
ConsoleLogger.LEVEL_INFO,
config,
"logkit-simple" );
}
public void testLogKitLoggerStoreFactoryWithStreamsAndDefaultLoggerManager()
throws Exception
{
final HashMap config = new HashMap();
runStreamBasedFactoryTest( "logkit-excalibur.xml",
new LogKitLoggerStoreFactory(),
ConsoleLogger.LEVEL_INFO,
"logkit-excalibur",
config );
}
public void testLogKitLoggerStoreFactoryWithStreamsAndLoggerManager()
throws Exception
{
final HashMap config = new HashMap();
config.put( LogKitLoggerStoreFactory.LOGGER_MANAGER,
SimpleLogKitManager.class.getName() );
runStreamBasedFactoryTest( "logkit-simple.xml",
new LogKitLoggerStoreFactory(),
ConsoleLogger.LEVEL_INFO,
"logkit-simple",
config );
}
public void testLogKitLoggerStoreFactoryWithStreamsAndInvalidLoggerManager()
throws Exception
{
final HashMap config = new HashMap();
config.put( LogKitLoggerStoreFactory.LOGGER_MANAGER,
"SomeInvalidLoggerManager" );
try
{
runStreamBasedFactoryTest( "logkit-simple.xml",
new LogKitLoggerStoreFactory(),
ConsoleLogger.LEVEL_INFO,
"logkit-simple",
config );
fail( "Expected to not be able to create LoggerManager ");
}
catch( final Exception e )
{
}
}
public void testExcaliburLogKitLoggerStoreFactoryInvalidInput()
throws Exception
{
runInvalidInputData( new ExcaliburLogKitLoggerStoreFactory() );
}
public void testExcaliburLogKitLoggerStoreFactoryWithConfiguration()
throws Exception
{
final DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
final HashMap config = new HashMap();
config.put( Configuration.class.getName(),
builder.build( getResource( "logkit-excalibur.xml" ) ) );
config.put( Logger.class.getName(), new ConsoleLogger() );
runFactoryTest( new ExcaliburLogKitLoggerStoreFactory(),
ConsoleLogger.LEVEL_INFO,
config,
"logkit-excalibur" );
}
public void testExcaliburLogKitLoggerStoreFactoryWithStreams()
throws Exception
{
runStreamBasedFactoryTest( "logkit-excalibur.xml",
new ExcaliburLogKitLoggerStoreFactory(),
ConsoleLogger.LEVEL_INFO,
"logkit-excalibur",
new HashMap() );
}
public void testSimpleLogKitLoggerStoreFactoryInvalidInput()
throws Exception
{
runInvalidInputData( new SimpleLogKitLoggerStoreFactory() );
}
public void testSimpleLogKitLoggerStoreFactoryWithConfiguration()
throws Exception
{
final DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
final HashMap config = new HashMap();
config.put( Configuration.class.getName(),
builder.build( getResource( "logkit-simple.xml" ) ) );
config.put( Logger.class.getName(), new ConsoleLogger() );
runFactoryTest( new SimpleLogKitLoggerStoreFactory(),
ConsoleLogger.LEVEL_INFO,
config,
"logkit-simple" );
}
public void testSimpleLogKitLoggerStoreFactoryWithStreams()
throws Exception
{
final HashMap config = new HashMap();
runStreamBasedFactoryTest( "logkit-simple.xml",
new SimpleLogKitLoggerStoreFactory(),
ConsoleLogger.LEVEL_INFO,
"logkit-simple",
config );
}
// Log4JLoggerStoreFactory tests
public void testPropertyLog4jLoggerStoreFactoryInvalidInput()
throws Exception
{
runInvalidInputData( new PropertyLog4JLoggerStoreFactory() );
}
public void testDOMLog4jLoggerStoreFactoryInvalidInput()
throws Exception
{
runInvalidInputData( new DOMLog4JLoggerStoreFactory() );
}
public void testLog4jLoggerStoreFactoryWithProperties()
throws Exception
{
final Properties properties = new Properties();
properties.load( getResource( "log4j.properties" ) );
final HashMap config = new HashMap();
config.put( Properties.class.getName(), properties );
runFactoryTest( new PropertyLog4JLoggerStoreFactory(),
ConsoleLogger.LEVEL_DEBUG,
config,
"log4j-properties" );
}
public void testLog4jLoggerStoreFactoryWithElement()
throws Exception
{
final HashMap config = new HashMap();
final Element element =
buildElement( getResource( "log4j.xml" ),
new org.apache.log4j.xml.Log4jEntityResolver(),
null );
config.put( Element.class.getName(), element );
runFactoryTest( new DOMLog4JLoggerStoreFactory(),
ConsoleLogger.LEVEL_DEBUG,
config,
"log4j-xml" );
}
public void testLog4JLoggerStoreFactoryWithStreamsAsXML()
throws Exception
{
runStreamBasedFactoryTest( "log4j.xml",
new DOMLog4JLoggerStoreFactory(),
ConsoleLogger.LEVEL_DEBUG,
"log4j-xml",
new HashMap() );
}
public void testLog4JLoggerStoreFactoryWithStreamsAsProperties()
throws Exception
{
final HashMap inputData = new HashMap();
runStreamBasedFactoryTest( "log4j.properties",
new PropertyLog4JLoggerStoreFactory(),
ConsoleLogger.LEVEL_DEBUG,
"log4j-properties",
inputData );
}
// JDK14LoggerStoreFactory tests
public void testJDK14LoggerStoreFactoryInvalidInput()
throws Exception
{
runInvalidInputData( new Jdk14LoggerStoreFactory() );
}
public void testJDK14LoggerStoreFactoryWithProperties()
throws Exception
{
final Properties properties = new Properties();
properties.load( getResource( "logging.properties" ) );
final HashMap config = new HashMap();
config.put( Properties.class.getName(), properties );
runFactoryTest( new Jdk14LoggerStoreFactory(),
ConsoleLogger.LEVEL_DEBUG,
config,
"jdk14" );
}
public void testJDK14LoggerStoreFactoryWithStreams()
throws Exception
{
runStreamBasedFactoryTest( "logging.properties",
new Jdk14LoggerStoreFactory(),
ConsoleLogger.LEVEL_DEBUG,
"jdk14",
new HashMap() );
}
}
1.1 spice/components/loggerstore/src/test/org/codehaus/spice/loggerstore/JDK14RawFormatter.java
Index: JDK14RawFormatter.java
===================================================================
/*
* Copyright (C) The Spice Group. All rights reserved.
*
* This software is published under the terms of the Spice
* Software License version 1.1, a copy of which has been included
* with this distribution in the LICENSE.txt file.
*/
package org.codehaus.spice.loggerstore;
import java.util.logging.Formatter;
import java.util.logging.LogRecord;
/**
* Class that extends base formatter to provide raw text output.
*
* @author <a href="mailto:peter at realityforge.org">Peter Donald</a>
* @version $Revision: 1.1 $ $Date: 2003/11/19 18:22:43 $
*/
public class JDK14RawFormatter
extends Formatter
{
public String format( final LogRecord record )
{
return formatMessage( record ) + "\n";
}
}
1.1 spice/components/loggerstore/src/test/org/codehaus/spice/loggerstore/logging.properties
Index: logging.properties
===================================================================
# comma separated list of log Handler
handlers= java.util.logging.FileHandler, java.util.logging.ConsoleHandler
# Default global logging level.
.level= INFO
# file handler
java.util.logging.FileHandler.pattern = logs/jdk14.log
java.util.logging.FileHandler.limit = 50000
java.util.logging.FileHandler.count = 1
java.util.logging.FileHandler.formatter = org.codehaus.spice.loggerstore.JDK14RawFormatter
# console handler
java.util.logging.ConsoleHandler.level = INFO
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
############################################################
# Facility specific properties.
# Provides extra control for each logger.
############################################################
# Set the logger to only log SEVERE
nejney.level = FINEST
1.1 spice/components/loggerstore/src/test/org/codehaus/spice/loggerstore/ConfiguratorTestCase.java
Index: ConfiguratorTestCase.java
===================================================================
/*
* Copyright (C) The Spice Group. All rights reserved.
*
* This software is published under the terms of the Spice
* Software License version 1.1, a copy of which has been included
* with this distribution in the LICENSE.txt file.
*/
package org.codehaus.spice.loggerstore;
import org.jcontainer.dna.impl.ConsoleLogger;
/**
* Test case for Configurator
*
* @author <a href="mailto:mauro.talevi at aquilonia.org">Mauro Talevi</a>
* @author <a href="mailto:peter at realityforge.org">Peter Donald</a>
*/
public class ConfiguratorTestCase
extends AbstractTestCase
{
public ConfiguratorTestCase( final String name )
{
super( name );
}
public void testInvalidConfiguratorType()
throws Exception
{
try
{
Configurator.createLoggerStore( "blah", "org/codehaus/spice/loggerstore/logging.properties" );
fail( "Expected exception as invalid type specified" );
}
catch( final Exception e )
{
}
}
public void testLogKitExcaliburConfigurator()
throws Exception
{
runLoggerTest( "logkit-excalibur", Configurator.createLoggerStore( Configurator.LOGKIT_EXCALIBUR, "org/codehaus/spice/loggerstore/logkit-excalibur.xml" ),
ConsoleLogger.LEVEL_DEBUG );
runLoggerTest( "logkit-excalibur", Configurator.createLoggerStore( Configurator.LOGKIT_EXCALIBUR, getResource( "logkit-excalibur.xml" )),
ConsoleLogger.LEVEL_DEBUG );
}
public void testLogKitExcaliburConfiguratorNoDebug()
throws Exception
{
runLoggerTest( "logkit-excalibur", Configurator.createLoggerStore( Configurator.LOGKIT_EXCALIBUR, "org/codehaus/spice/loggerstore/logkit-excalibur.xml" ),
ConsoleLogger.LEVEL_NONE );
runLoggerTest( "logkit-excalibur", Configurator.createLoggerStore( Configurator.LOGKIT_EXCALIBUR, getResource( "logkit-excalibur.xml" )),
ConsoleLogger.LEVEL_NONE );
}
public void testLogKitExcaliburConfiguratorNoLog()
throws Exception
{
runLoggerTest( "logkit-excalibur", Configurator.createLoggerStore( Configurator.LOGKIT_EXCALIBUR, "org/codehaus/spice/loggerstore/logkit-excalibur.xml" ) );
runLoggerTest( "logkit-excalibur", Configurator.createLoggerStore( Configurator.LOGKIT_EXCALIBUR, getResource( "logkit-excalibur.xml" )) );
}
public void testLogKitSimpleConfigurator()
throws Exception
{
runLoggerTest( "logkit-simple", Configurator.createLoggerStore( Configurator.LOGKIT_SIMPLE, "org/codehaus/spice/loggerstore/logkit-simple.xml" ),
ConsoleLogger.LEVEL_DEBUG );
runLoggerTest( "logkit-simple", Configurator.createLoggerStore( Configurator.LOGKIT_SIMPLE, getResource( "logkit-simple.xml" )),
ConsoleLogger.LEVEL_DEBUG );
}
public void testLogKitSimpleConfiguratorNoDebug()
throws Exception
{
runLoggerTest( "logkit-simple", Configurator.createLoggerStore( Configurator.LOGKIT_SIMPLE, "org/codehaus/spice/loggerstore/logkit-simple.xml" ),
ConsoleLogger.LEVEL_NONE );
runLoggerTest( "logkit-simple", Configurator.createLoggerStore( Configurator.LOGKIT_SIMPLE, getResource( "logkit-simple.xml" )),
ConsoleLogger.LEVEL_NONE );
}
public void testLogKitSimpleConfiguratorNoLog()
throws Exception
{
runLoggerTest( "logkit-simple", Configurator.createLoggerStore( Configurator.LOGKIT_SIMPLE, "org/codehaus/spice/loggerstore/logkit-simple.xml" ) );
runLoggerTest( "logkit-simple", Configurator.createLoggerStore( Configurator.LOGKIT_SIMPLE, getResource( "logkit-simple.xml" )) );
}
public void testLog4JDOMConfigurator()
throws Exception
{
runLoggerTest( "log4j-xml", Configurator.createLoggerStore( Configurator.LOG4J_DOM, "org/codehaus/spice/loggerstore/log4j.xml" ),
ConsoleLogger.LEVEL_DEBUG );
runLoggerTest( "log4j-xml", Configurator.createLoggerStore( Configurator.LOG4J_DOM, getResource( "log4j.xml" )),
ConsoleLogger.LEVEL_DEBUG );
}
public void testLog4JDOMConfiguratorNoDebug()
throws Exception
{
runLoggerTest( "log4j-xml", Configurator.createLoggerStore( Configurator.LOG4J_DOM, "org/codehaus/spice/loggerstore/log4j.xml" ),
ConsoleLogger.LEVEL_NONE );
runLoggerTest( "log4j-xml", Configurator.createLoggerStore( Configurator.LOG4J_DOM, getResource( "log4j.xml" )),
ConsoleLogger.LEVEL_NONE );
}
public void testLog4JDOMConfiguratorNoLog()
throws Exception
{
runLoggerTest( "log4j-xml", Configurator.createLoggerStore( Configurator.LOG4J_DOM, "org/codehaus/spice/loggerstore/log4j.xml" ) );
runLoggerTest( "log4j-xml", Configurator.createLoggerStore( Configurator.LOG4J_DOM, getResource( "log4j.xml" )) );
}
public void testLog4JPropertyConfigurator()
throws Exception
{
runLoggerTest( "log4j-properties", Configurator.createLoggerStore( Configurator.LOG4J_PROPERTY, "org/codehaus/spice/loggerstore/log4j.properties" ),
ConsoleLogger.LEVEL_DEBUG );
runLoggerTest( "log4j-properties", Configurator.createLoggerStore( Configurator.LOG4J_PROPERTY, getResource( "log4j.properties" )),
ConsoleLogger.LEVEL_DEBUG );
}
public void testLog4JPropertyConfiguratorNoDebug()
throws Exception
{
runLoggerTest( "log4j-properties", Configurator.createLoggerStore( Configurator.LOG4J_PROPERTY, "org/codehaus/spice/loggerstore/log4j.properties" ),
ConsoleLogger.LEVEL_NONE );
runLoggerTest( "log4j-properties", Configurator.createLoggerStore( Configurator.LOG4J_PROPERTY, getResource( "log4j.properties" )),
ConsoleLogger.LEVEL_NONE );
}
public void testLog4JPropertyConfiguratorNoLog()
throws Exception
{
runLoggerTest( "log4j-properties", Configurator.createLoggerStore( Configurator.LOG4J_PROPERTY, "org/codehaus/spice/loggerstore/log4j.properties" ) );
runLoggerTest( "log4j-properties", Configurator.createLoggerStore( Configurator.LOG4J_PROPERTY, getResource( "log4j.properties" )) );
}
public void testJDK14Configurator()
throws Exception
{
runLoggerTest( "jdk14", Configurator.createLoggerStore( Configurator.JDK14, "org/codehaus/spice/loggerstore/logging.properties" ),
ConsoleLogger.LEVEL_DEBUG );
runLoggerTest( "jdk14", Configurator.createLoggerStore( Configurator.JDK14, getResource( "logging.properties" )),
ConsoleLogger.LEVEL_DEBUG );
}
public void testJDK14ConfiguratorNoDebug()
throws Exception
{
runLoggerTest( "jdk14", Configurator.createLoggerStore( Configurator.JDK14, "org/codehaus/spice/loggerstore/logging.properties" ),
ConsoleLogger.LEVEL_NONE );
runLoggerTest( "jdk14", Configurator.createLoggerStore( Configurator.JDK14, getResource( "logging.properties" )),
ConsoleLogger.LEVEL_NONE );
}
public void testJDK14ConfiguratorNoLog()
throws Exception
{
runLoggerTest( "jdk14", Configurator.createLoggerStore( Configurator.JDK14, "org/codehaus/spice/loggerstore/logging.properties" ) );
runLoggerTest( "jdk14", Configurator.createLoggerStore( Configurator.JDK14, getResource( "logging.properties" )) );
}
}
1.1 spice/components/loggerstore/src/test/org/codehaus/spice/loggerstore/AbstractTestCase.java
Index: AbstractTestCase.java
===================================================================
/*
* Copyright (C) The Spice Group. All rights reserved.
*
* This software is published under the terms of the Spice
* Software License version 1.1, a copy of which has been included
* with this distribution in the LICENSE.txt file.
*/
package org.codehaus.spice.loggerstore;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.HashMap;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.FactoryConfigurationError;
import junit.framework.TestCase;
import org.jcontainer.dna.Logger;
import org.jcontainer.dna.impl.ContainerUtil;
import org.jcontainer.dna.impl.ConsoleLogger;
import org.codehaus.spice.loggerstore.stores.Jdk14LoggerStore;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
/**
* AbstactLoggerStoreTestCase
*
* @author <a href="mailto:mauro.talevi at aquilonia.org">Mauro Talevi</a>
* @author <a href="mailto:peter at realityforge.org">Peter Donald</a>
*/
public class AbstractTestCase
extends TestCase
{
protected static final String MESSAGE = "Testing Logger";
protected static final String MESSAGE2 = "This occurs in sub-category";
private File m_logsDir;
public AbstractTestCase( final String name )
{
super( name );
}
protected void setUp() throws Exception
{
m_logsDir = new File( "logs/" );
m_logsDir.mkdirs();
}
protected final InputStream getResource( final String name )
{
return getClass().getResourceAsStream( name );
}
protected void runLoggerTest( final String filename,
final LoggerStore store,
final int level )
throws Exception
{
ContainerUtil.enableLogging( store, new ConsoleLogger( level ) );
runLoggerTest( filename, store );
}
protected void runLoggerTest( final String filename,
final LoggerStore store )
throws Exception
{
BufferedReader reader = null;
try
{
final Logger logger = store.getLogger();
assertNotNull( "rootLogger for " + filename, logger );
logger.info( MESSAGE );
final Logger noExistLogger = store.getLogger( "no-exist" );
assertNotNull( "noExistLogger for " + filename, noExistLogger );
noExistLogger.info( MESSAGE2 );
assertEquals( "Same Logger returned multiple times:",
noExistLogger,
store.getLogger( "no-exist" ) );
try
{
store.getLogger( null );
fail( "Expected a NullPointerException when passing " +
"null in for getLogger parameter" );
}
catch( final NullPointerException npe )
{
assertEquals( "NullPointer message", "name", npe.getMessage() );
}
final File logFile = new File( m_logsDir, filename + ".log" );
assertTrue( "Checking LogFile Exists: " + filename, logFile.exists() );
reader = new BufferedReader( new InputStreamReader( new FileInputStream( logFile ) ) );
assertEquals( "First line Contents for logger" + filename,
MESSAGE, reader.readLine() );
assertEquals( "Second line Contents for logger" + filename,
MESSAGE2, reader.readLine() );
assertNull( "Third Line Contents for logger" + filename,
reader.readLine() );
reader.close();
logFile.delete();
if( !( store instanceof Jdk14LoggerStore ) )
{
final Logger nejney = store.getLogger( "nejney" );
nejney.info( MESSAGE );
final File logFile2 = new File( m_logsDir, filename + "2.log" );
reader = new BufferedReader( new InputStreamReader( new FileInputStream( logFile2 ) ) );
assertEquals( "First line Contents for nejney logger" + filename,
MESSAGE, reader.readLine() );
assertNull( "Second Line Contents for nejney logger" + filename,
reader.readLine() );
reader.close();
logFile2.delete();
}
}
finally
{
store.close();
if( null != reader )
{
reader.close();
}
}
}
/**
* Builds an Element from a resource
* @param resource the InputStream of the configuration resource
* @param resolver the EntityResolver required by the DocumentBuilder -
* or <code>null</code> if none required
* @param systemId the String encoding the systemId required by the InputSource -
* or <code>null</code> if none required
*/
protected static Element buildElement( final InputStream resource,
final EntityResolver resolver,
final String systemId )
throws Exception
{
DocumentBuilderFactory dbf = null;
try
{
dbf = DocumentBuilderFactory.newInstance();
}
catch( FactoryConfigurationError e )
{
final String message = "Failed to create a DocumentBuilderFactory";
throw new Exception( message, e );
}
try
{
dbf.setValidating( true );
DocumentBuilder db = dbf.newDocumentBuilder();
if( resolver != null )
{
db.setEntityResolver( resolver );
}
InputSource source = new InputSource( resource );
if( systemId != null )
{
source.setSystemId( systemId );
}
Document doc = db.parse( source );
return doc.getDocumentElement();
}
catch( Exception e )
{
final String message = "Failed to parse Document";
throw new Exception( message, e );
}
}
protected void performConsoleTest( final LoggerStore store, final int level ) throws Exception
{
ContainerUtil.enableLogging( store, new ConsoleLogger( level ) );
final Logger logger = store.getLogger();
assertNotNull( "rootLogger for console", logger );
logger.info( MESSAGE );
final Logger noExistLogger = store.getLogger( "no-exist" );
assertNotNull( "noExistLogger for console", noExistLogger );
noExistLogger.info( MESSAGE2 );
store.close();
}
protected void runInvalidInputData( final LoggerStoreFactory factory )
{
try
{
factory.createLoggerStore( new HashMap() );
fail( "Expected createLoggerStore to fail with invalid input data" );
}
catch( Exception e )
{
}
}
protected void runStreamBasedFactoryTest( final String inputFile,
final LoggerStoreFactory factory,
final int level,
final String outputFile,
final HashMap inputData )
throws Exception
{
//URL Should in file: format
final URL url = getClass().getResource( inputFile );
assertEquals( "URL is of file type", url.getProtocol(), "file" );
final HashMap config = new HashMap();
config.put( LoggerStoreFactory.URL_LOCATION,
url.toExternalForm() );
config.putAll( inputData );
runFactoryTest( factory,
level,
config,
outputFile );
final HashMap config2 = new HashMap();
config2.put( URL.class.getName(), url );
config2.putAll( inputData );
runFactoryTest( factory,
level,
config2,
outputFile );
final String filename = url.toExternalForm().substring( 5 );
final HashMap config3 = new HashMap();
config3.put( LoggerStoreFactory.FILE_LOCATION, filename );
config3.putAll( inputData );
runFactoryTest( factory,
level,
config3,
outputFile );
final HashMap config4 = new HashMap();
config4.put( File.class.getName(), new File( filename ) );
config4.putAll( inputData );
runFactoryTest( factory,
level,
config4,
outputFile );
final HashMap config5 = new HashMap();
config5.put( InputStream.class.getName(),
new FileInputStream( filename ) );
config5.putAll( inputData );
runFactoryTest( factory,
level,
config5,
outputFile );
}
protected void runFactoryTest( final LoggerStoreFactory factory, final int level, final HashMap config, final String filename ) throws Exception
{
ContainerUtil.enableLogging( factory, new ConsoleLogger( level ) );
final LoggerStore store = factory.createLoggerStore( config );
runLoggerTest( filename, store, level );
}
}
1.1 spice/components/loggerstore/src/java/org/codehaus/spice/loggerstore/stores/Jdk14LoggerStore.java
Index: Jdk14LoggerStore.java
===================================================================
/*
* Copyright (C) The Spice Group. All rights reserved.
*
* This software is published under the terms of the Spice
* Software License version 1.1, a copy of which has been included
* with this distribution in the LICENSE.txt file.
*/
package org.codehaus.spice.loggerstore.stores;
import java.io.InputStream;
import java.util.logging.LogManager;
import org.jcontainer.dna.Logger;
import org.jcontainer.dna.impl.Jdk14Logger;
/**
* Jdk14LoggerStore extends AbstractLoggerStore to provide the implementation
* specific to the JDK14 logger.
*
* @author <a href="mailto:mauro.talevi at aquilonia.org">Mauro Talevi</a>
*/
public class Jdk14LoggerStore
extends AbstractLoggerStore
{
/** The LogManager repository */
private final LogManager m_manager;
/**
* Creates a <code>Log4JLoggerStore</code> using the configuration resource.
*
* @param resource the InputStream encoding the configuration resource
* @throws Exception if fails to create or configure Logger
*/
public Jdk14LoggerStore( final InputStream resource )
throws Exception
{
m_manager = LogManager.getLogManager();
m_manager.readConfiguration( resource );
setRootLogger( new Jdk14Logger( m_manager.getLogger( "global" ) ) );
}
/**
* Creates new Jdk14Logger for the given category.
*/
protected Logger createLogger( final String name )
{
return new Jdk14Logger( java.util.logging.Logger.getLogger( name ) );
}
/**
* Closes the LoggerStore and shuts down the logger hierarchy.
*/
public void close()
{
m_manager.reset();
}
}
1.1 spice/components/loggerstore/src/java/org/codehaus/spice/loggerstore/stores/AbstractLoggerStore.java
Index: AbstractLoggerStore.java
===================================================================
/*
* Copyright (C) The Spice Group. All rights reserved.
*
* This software is published under the terms of the Spice
* Software License version 1.1, a copy of which has been included
* with this distribution in the LICENSE.txt file.
*/
package org.codehaus.spice.loggerstore.stores;
import java.util.HashMap;
import java.util.Map;
import org.codehaus.spice.loggerstore.LoggerStore;
import org.jcontainer.dna.LogEnabled;
import org.jcontainer.dna.Logger;
/**
* AbstractLoggerStore is an abstract implementation of LoggerStore for the
* functionality common to all Loggers.
*
* @author <a href="mailto:mauro.talevi at aquilonia.org">Mauro Talevi</a>
*/
public abstract class AbstractLoggerStore
implements LoggerStore, LogEnabled
{
/** Map of Loggers held in the store */
private final Map m_loggers = new HashMap();
/** The Logger used by LogEnabled. */
private Logger m_logger;
/** The root Logger */
private Logger m_rootLogger;
/**
* Provide a logger.
*
* @param logger the logger
*/
public void enableLogging( final Logger logger )
{
m_logger = logger;
}
/**
* Retrieves the root Logger from the store.
* @return the Logger
* @throws Exception if unable to retrieve Logger
*/
public Logger getLogger()
throws Exception
{
if( m_logger != null && m_logger.isDebugEnabled() )
{
final String message = "Root Logger returned";
m_logger.debug( message );
}
final Logger logger = getRootLogger();
if( logger == null )
{
final String message = "Root Logger is not defined";
throw new Exception( message );
}
return logger;
}
/**
* Retrieves a Logger hierarchy from the store for a given category name.
*
* @param name the name of the logger.
* @return the Logger
* @throws Exception if unable to retrieve Logger
*/
public Logger getLogger( final String name )
throws Exception
{
if( null == name )
{
throw new NullPointerException( "name" );
}
Logger logger = retrieveLogger( name );
if( logger == null )
{
if( m_logger != null && m_logger.isDebugEnabled() )
{
final String message = "Logger named '" + name +
"' not defined in configuration. New Logger " +
"created and returned.";
m_logger.debug( message );
}
logger = createLogger( name );
final Logger logger1 = logger;
m_loggers.put( name, logger1 );
}
return logger;
}
/**
* Creates new Logger for the given category.
* This is logger-implementation specific and will be implemented in
* concrete subclasses.
*/
protected abstract Logger createLogger( String name );
/**
* Sets the root Logger.
*/
protected final void setRootLogger( final Logger rootLogger )
{
m_rootLogger = rootLogger;
}
/**
* Returns the root logger.
*
* @return the root logger.
*/
protected final Logger getRootLogger()
{
return m_rootLogger;
}
/**
* Retrieve Logger from store map.
*
* @param name the name of the Logger
* @return the Logger instance or <code>null</code> if not found in map.
*/
private Logger retrieveLogger( final String name )
{
Logger logger = (Logger)m_loggers.get( name );
if( null != logger )
{
if( null != m_logger && m_logger.isDebugEnabled() )
{
final String message = "Retrieved Logger named: " + name;
m_logger.debug( message );
}
}
return logger;
}
}
1.1 spice/components/loggerstore/src/java/org/codehaus/spice/loggerstore/stores/Log4JLoggerStore.java
Index: Log4JLoggerStore.java
===================================================================
/*
* Copyright (C) The Spice Group. All rights reserved.
*
* This software is published under the terms of the Spice
* Software License version 1.1, a copy of which has been included
* with this distribution in the LICENSE.txt file.
*/
package org.codehaus.spice.loggerstore.stores;
import java.io.InputStream;
import java.util.Properties;
import org.apache.log4j.LogManager;
import org.apache.log4j.PropertyConfigurator;
import org.apache.log4j.spi.LoggerRepository;
import org.apache.log4j.xml.DOMConfigurator;
import org.jcontainer.dna.Logger;
import org.jcontainer.dna.impl.Log4JLogger;
import org.w3c.dom.Element;
/**
* Log4JLoggerStore extends AbstractLoggerStore to provide the implementation
* specific to the Log4J logger.
*
* @author <a href="mailto:mauro.talevi at aquilonia.org">Mauro Talevi</a>
*/
public class Log4JLoggerStore
extends AbstractLoggerStore
{
/** The logger repository */
private final LoggerRepository m_repository;
/**
* Creates a <code>Log4JLoggerStore</code> using the configuration resource
* @param resource the Element encoding the configuration resource
* @throws Exception if fails to create or configure Logger
*/
public Log4JLoggerStore( final Element resource )
throws Exception
{
LogManager.resetConfiguration();
m_repository = LogManager.getLoggerRepository();
final DOMConfigurator configurator = new DOMConfigurator();
configurator.doConfigure( resource, m_repository );
setRootLogger( new Log4JLogger( m_repository.getRootLogger() ) );
}
/**
* Creates a <code>Log4JLoggerStore</code> using the configuration resource
* @param resource the InputStream encoding the configuration resource
* @throws Exception if fails to create or configure Logger
*/
public Log4JLoggerStore( final InputStream resource )
throws Exception
{
LogManager.resetConfiguration();
m_repository = LogManager.getLoggerRepository();
final DOMConfigurator configurator = new DOMConfigurator();
configurator.doConfigure( resource, m_repository );
setRootLogger( new Log4JLogger( m_repository.getRootLogger() ) );
}
/**
* Creates a <code>Log4JLoggerStore</code> using the configuration resource
* @param resource the Properties encoding the configuration resource
* @throws Exception if fails to create or configure Logger
*/
public Log4JLoggerStore( final Properties resource )
throws Exception
{
LogManager.resetConfiguration();
m_repository = LogManager.getLoggerRepository();
final PropertyConfigurator configurator = new PropertyConfigurator();
configurator.doConfigure( resource, m_repository );
setRootLogger( new Log4JLogger( m_repository.getRootLogger() ) );
}
/**
* Creates new Log4JLogger for the given category.
*/
protected Logger createLogger( final String categoryName )
{
return new Log4JLogger( m_repository.getLogger( categoryName ) );
}
/**
* Closes the LoggerStore and shuts down the logger hierarchy.
*/
public void close()
{
m_repository.shutdown();
}
}
1.1 spice/components/loggerstore/src/java/org/codehaus/spice/loggerstore/stores/ConsoleLoggerStore.java
Index: ConsoleLoggerStore.java
===================================================================
/*
* Copyright (C) The Spice Group. All rights reserved.
*
* This software is published under the terms of the Spice
* Software License version 1.1, a copy of which has been included
* with this distribution in the LICENSE.txt file.
*/
package org.codehaus.spice.loggerstore.stores;
import org.jcontainer.dna.Logger;
import org.jcontainer.dna.impl.ConsoleLogger;
/**
* ConsoleLoggerStore extends AbstractLoggerStore to provide the implementation
* specific that just writes to console.
*
* @author <a href="mailto:mauro.talevi at aquilonia.org">Mauro Talevi</a>
*/
public class ConsoleLoggerStore
extends AbstractLoggerStore
{
/**
* Creates a <code>ConsoleLoggerStore</code> using the specified Logger level.
*
* @param level the debug level of ConsoleLoggerStore
* @throws Exception if fails to create or configure Logger
*/
public ConsoleLoggerStore( final int level )
throws Exception
{
setRootLogger( new ConsoleLogger( level ) );
}
/**
* Creates new ConsoleLogger for the given category.
*/
protected Logger createLogger( final String name )
{
return getRootLogger().getChildLogger( name );
}
/**
* Closes the LoggerStore and shuts down the logger hierarchy.
*/
public void close()
{
}
}
1.1 spice/components/loggerstore/src/java/org/codehaus/spice/loggerstore/stores/LogKitLoggerStore.java
Index: LogKitLoggerStore.java
===================================================================
/*
* Copyright (C) The Spice Group. All rights reserved.
*
* This software is published under the terms of the Spice
* Software License version 1.1, a copy of which has been included
* with this distribution in the LICENSE.txt file.
*/
package org.codehaus.spice.loggerstore.stores;
import org.apache.avalon.excalibur.logger.LoggerManager;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.container.ContainerUtil;
import org.apache.avalon.framework.context.Context;
import org.apache.avalon.framework.context.DefaultContext;
import org.apache.avalon.framework.logger.Logger;
import org.apache.avalon.framework.logger.NullLogger;
import org.jcomponent.alchemist.LoggerAlchemist;
/**
* <p>LogKitLoggerStore extends AbstractLoggerStore to provide the implementation
* specific to the LogKit logger. </p>
*
* @author <a href="mailto:mauro.talevi at aquilonia.org">Mauro Talevi</a>
*/
public class LogKitLoggerStore
extends AbstractLoggerStore
{
/** The Logger Manager */
private final LoggerManager m_loggerManager;
/**
* Creates a <code>LogKitLoggerStore</code> using the given configuration
*
* @param loggerManager the LoggerManager used to configure the store
* @param logger the Logger to logEnable the LoggerManager
* @param context the Context of the LoggerManager
* @param configuration the logger configuration
* @throws Exception if fails to create or configure Logger
*/
public LogKitLoggerStore( final LoggerManager loggerManager,
final Logger logger,
final Context context,
final Configuration configuration )
throws Exception
{
if( null == loggerManager )
{
throw new NullPointerException( "loggerManager" );
}
m_loggerManager = loggerManager;
if( null != logger )
{
ContainerUtil.enableLogging( m_loggerManager, logger );
}
else
{
ContainerUtil.enableLogging( m_loggerManager, new NullLogger() );
}
if( null != context )
{
ContainerUtil.contextualize( m_loggerManager, context );
}
else
{
ContainerUtil.contextualize( m_loggerManager, new DefaultContext() );
}
ContainerUtil.configure( m_loggerManager, configuration );
setRootLogger( LoggerAlchemist.toDNALogger( m_loggerManager.getDefaultLogger() ) );
}
/**
* Creates new LogKitLogger for the given category.
*/
protected org.jcontainer.dna.Logger createLogger( final String name )
{
return LoggerAlchemist.toDNALogger( m_loggerManager.getLoggerForCategory( name ) );
}
/**
* Closes the LoggerStore and shuts down the logger hierarchy.
*/
public void close()
{
try
{
ContainerUtil.shutdown( m_loggerManager );
}
catch( Exception e )
{
}
}
}
1.1 spice/components/loggerstore/src/java/org/codehaus/spice/loggerstore/factories/SimpleLogKitLoggerStoreFactory.java
Index: SimpleLogKitLoggerStoreFactory.java
===================================================================
/*
* Copyright (C) The Spice Group. All rights reserved.
*
* This software is published under the terms of the Spice
* Software License version 1.1, a copy of which has been included
* with this distribution in the LICENSE.txt file.
*/
package org.codehaus.spice.loggerstore.factories;
import java.util.Map;
import org.apache.avalon.excalibur.logger.LoggerManager;
import org.apache.avalon.excalibur.logger.SimpleLogKitManager;
import org.codehaus.spice.loggerstore.LoggerStore;
/**
* SimpleLogKitLoggerStoreFactory specialises the LogKitLoggerStoreFactory
* to use the SimpleLogKitManager.
*
* @author <a href="mailto:mauro.talevi at aquilonia.org">Mauro Talevi</a>
*/
public class SimpleLogKitLoggerStoreFactory
extends LogKitLoggerStoreFactory
{
/**
* Creates a LoggerStore from a given set of configuration parameters.
*
* @param config the Map of parameters for the configuration of the store
* @return the LoggerStore
* @throws Exception if unable to create the LoggerStore
*/
protected LoggerStore doCreateLoggerStore( final Map config )
throws Exception
{
final LoggerManager loggerManager = new SimpleLogKitManager();
config.put( LoggerManager.class.getName(), loggerManager );
return super.doCreateLoggerStore( config );
}
}
1.1 spice/components/loggerstore/src/java/org/codehaus/spice/loggerstore/factories/Jdk14LoggerStoreFactory.java
Index: Jdk14LoggerStoreFactory.java
===================================================================
/*
* Copyright (C) The Spice Group. All rights reserved.
*
* This software is published under the terms of the Spice
* Software License version 1.1, a copy of which has been included
* with this distribution in the LICENSE.txt file.
*/
package org.codehaus.spice.loggerstore.factories;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.util.Map;
import java.util.Properties;
import org.codehaus.spice.loggerstore.LoggerStore;
import org.codehaus.spice.loggerstore.stores.Jdk14LoggerStore;
/**
* Jdk14LoggerStoreFactory is an implementation of LoggerStoreFactory
* for the JDK14 Logger.
*
* @author <a href="mailto:mauro.talevi at aquilonia.org">Mauro Talevi</a>
* @author <a href="mailto:peter at realityforge.org">Peter Donald</a>
* @version $Revision: 1.1 $ $Date: 2003/11/19 18:22:44 $
*/
public class Jdk14LoggerStoreFactory
extends AbstractLoggerStoreFactory
{
/**
* Creates a LoggerStore from a given set of configuration parameters.
*
* @param config the Map of parameters for the configuration of the store
* @return the LoggerStore
* @throws Exception if unable to create the LoggerStore
*/
protected LoggerStore doCreateLoggerStore( final Map config )
throws Exception
{
final Properties properties = (Properties)config.get( Properties.class.getName() );
if( null != properties )
{
final ByteArrayOutputStream output = new ByteArrayOutputStream();
properties.store( output, "" );
final ByteArrayInputStream input = new ByteArrayInputStream( output.toByteArray() );
return new Jdk14LoggerStore( input );
}
final InputStream resource = getInputStream( config );
if( null != resource )
{
return new Jdk14LoggerStore( resource );
}
return missingConfiguration();
}
}
1.1 spice/components/loggerstore/src/java/org/codehaus/spice/loggerstore/factories/LogKitLoggerStoreFactory.java
Index: LogKitLoggerStoreFactory.java
===================================================================
/*
* Copyright (C) The Spice Group. All rights reserved.
*
* This software is published under the terms of the Spice
* Software License version 1.1, a copy of which has been included
* with this distribution in the LICENSE.txt file.
*/
package org.codehaus.spice.loggerstore.factories;
import java.io.InputStream;
import java.util.Map;
import org.apache.avalon.excalibur.logger.LogKitLoggerManager;
import org.apache.avalon.excalibur.logger.LoggerManager;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
import org.apache.avalon.framework.context.Context;
import org.apache.avalon.framework.logger.Logger;
import org.codehaus.spice.loggerstore.LoggerStore;
import org.codehaus.spice.loggerstore.stores.LogKitLoggerStore;
/**
* LogKitLoggerStoreFactory is an implementation of LoggerStoreFactory
* for the LogKit Logger.
*
* @author <a href="mailto:mauro.talevi at aquilonia.org">Mauro Talevi</a>
* @author <a href="mailto:peter at realityforge.org">Peter Donald</a>
* @version $Revision: 1.1 $ $Date: 2003/11/19 18:22:44 $
*/
public class LogKitLoggerStoreFactory
extends AbstractLoggerStoreFactory
{
/**
* The LOGGER_MANAGER key. Used to define the classname of the
* LoggerManager to use in creating a LogKitLoggerStore when not specified in the
* configuration map.
*/
public static final String LOGGER_MANAGER = "org.codehaus.spice.loggerstore.logkit.loggermanager";
/**
* The default LoggerManager class name
*/
private static final String DEFAULT_LOGGER_MANAGER = LogKitLoggerManager.class.getName();
/**
* Creates a LoggerStore from a given set of configuration parameters.
*
* @param config the Map of parameters for the configuration of the store
* @return the LoggerStore
* @throws Exception if unable to create the LoggerStore
*/
protected LoggerStore doCreateLoggerStore( final Map config )
throws Exception
{
LoggerManager loggerManager =
(LoggerManager)config.get( LoggerManager.class.getName() );
if( null == loggerManager )
{
String type = (String)config.get( LOGGER_MANAGER );
if( null == type )
{
type = DEFAULT_LOGGER_MANAGER;
}
final ClassLoader classLoader = getClassLoader( config );
loggerManager = createLoggerManager( type, classLoader );
}
Logger logger =
(Logger)config.get( Logger.class.getName() );
if( null == logger )
{
logger = loggerManager.getDefaultLogger();
}
final Context context =
(Context)config.get( Context.class.getName() );
final Configuration configuration =
(Configuration)config.get( Configuration.class.getName() );
if( null != configuration )
{
return new LogKitLoggerStore( loggerManager, logger, context, configuration );
}
final InputStream resource = getInputStream( config );
if( null != resource )
{
final DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
return new LogKitLoggerStore( loggerManager, logger, context, builder.build( resource ) );
}
return missingConfiguration();
}
/**
* Retrieve the classloader from data map. If no classloader is specified
* then use ContextClassLoader. If ContextClassLoader not specified then
* use ClassLoader that loaded this class.
*
* @param data the configuration data
* @return a ClassLoader
*/
protected ClassLoader getClassLoader( final Map data )
{
ClassLoader loader = (ClassLoader)data.get( ClassLoader.class.getName() );
if( null == loader )
{
loader = Thread.currentThread().getContextClassLoader();
if( null == loader )
{
loader = LogKitLoggerStoreFactory.class.getClassLoader();
}
}
return loader;
}
/**
* Create a {@link LoggerManager} for specified type.
*
* @param type the type of the LoggerManager to use.
* @return the created {@link LoggerManager}
*/
private LoggerManager createLoggerManager( final String type,
final ClassLoader classLoader )
{
try
{
final Class clazz = classLoader.loadClass( type );
return (LoggerManager)clazz.newInstance();
}
catch( final Exception e )
{
final String message =
"Failed to created LoggerManager: " + type;
throw new IllegalArgumentException( message );
}
}
}
1.1 spice/components/loggerstore/src/java/org/codehaus/spice/loggerstore/factories/InitialLoggerStoreFactory.java
Index: InitialLoggerStoreFactory.java
===================================================================
/*
* Copyright (C) The Spice Group. All rights reserved.
*
* This software is published under the terms of the Spice
* Software License version 1.1, a copy of which has been included
* with this distribution in the LICENSE.txt file.
*/
package org.codehaus.spice.loggerstore.factories;
import java.io.InputStream;
import java.net.URL;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import org.codehaus.spice.loggerstore.LoggerStore;
import org.codehaus.spice.loggerstore.LoggerStoreFactory;
/**
* This is the initial LoggerStoreFactory tyhat the user accesses
* to create their LoggerStore when the type is configurable.
*
* @author <a href="mailto:peter at realityforge.org">Peter Donald</a>
* @author <a href="mailto:mauro.talevi at aquilonia.org">Mauro Talevi</a>
* @version $Revision: 1.1 $ $Date: 2003/11/19 18:22:44 $
*/
public class InitialLoggerStoreFactory
implements LoggerStoreFactory
{
/**
* The INITIAL_FACTORY key. Used to define the classname of the
* initial LoggerStoreFactory. If not specified will attempt to use
* the ConsoleLoggerStoreFactory.
*/
public static final String INITIAL_FACTORY = "org.codehaus.spice.loggerstore.factory";
/**
* The name of properties file loaded from ClassLoader. This property
* file will be used to load default configuration settings if user failed
* to specify them.
*/
public static final String DEFAULT_PROPERTIES = "META-INF/spice/loggerstore.properties";
/**
* Create LoggerStore by first determining the correct LoggerStoreFactory
* to use and then delegating to that factory. See Class Javadocs for the
* process of locating LoggerStore.
*
* @param config the input configuration
* @return the LoggerStore
* @throws Exception if unable to create the LoggerStore for any reason.
*/
public LoggerStore createLoggerStore( final Map config )
throws Exception
{
final ClassLoader classLoader = getClassLoader( config );
String type = (String)config.get( INITIAL_FACTORY );
Map data = config;
if( null == type )
{
data = loadDefaultConfig( data, classLoader );
type = (String)data.get( INITIAL_FACTORY );
}
final LoggerStoreFactory factory =
createLoggerStoreFactory( type, classLoader );
return factory.createLoggerStore( data );
}
/**
* Retrieve the classloader from data map. If no classloader is specified
* then use ContextClassLoader. If ContextClassLoader not specified then
* use ClassLoader that loaded this class.
*
* @param data the configuration data
* @return a ClassLoader
*/
private ClassLoader getClassLoader( final Map data )
{
ClassLoader loader = (ClassLoader)data.get( ClassLoader.class.getName() );
if( null == loader )
{
loader = Thread.currentThread().getContextClassLoader();
if( null == loader )
{
loader = InitialLoggerStoreFactory.class.getClassLoader();
}
}
return loader;
}
/**
* Load the default properties for LoggerStoreFactory.
*
* @param initial the input data
* @param classLoader the classLoader to load properties files from
* @return the new configuration data
* @throws Exception if unable to load properties
*/
private Map loadDefaultConfig( final Map initial,
final ClassLoader classLoader )
throws Exception
{
final HashMap map = new HashMap();
final Enumeration resources =
classLoader.getResources( DEFAULT_PROPERTIES );
while( resources.hasMoreElements() )
{
final URL url = (URL)resources.nextElement();
final InputStream stream = url.openStream();
final Properties properties = new Properties();
properties.load( stream );
map.putAll( properties );
}
map.putAll( initial );
return map;
}
/**
* Create a {@link LoggerStoreFactory} for specified loggerType.
*
* @param type the type of the Logger to use.
* @return the created {@link LoggerStoreFactory}
*/
private LoggerStoreFactory createLoggerStoreFactory( final String type,
final ClassLoader classLoader )
{
if( null == type )
{
final String message = "No LoggerStoreFactory type specified.";
throw new IllegalStateException( message );
}
try
{
final Class clazz = classLoader.loadClass( type );
return (LoggerStoreFactory)clazz.newInstance();
}
catch( final Exception e )
{
final String message =
"Failed to created LoggerStoreFactory " + type;
throw new IllegalArgumentException( message );
}
}
}
1.1 spice/components/loggerstore/src/java/org/codehaus/spice/loggerstore/factories/DOMLog4JLoggerStoreFactory.java
Index: DOMLog4JLoggerStoreFactory.java
===================================================================
/*
* Copyright (C) The Spice Group. All rights reserved.
*
* This software is published under the terms of the Spice
* Software License version 1.1, a copy of which has been included
* with this distribution in the LICENSE.txt file.
*/
package org.codehaus.spice.loggerstore.factories;
import java.io.InputStream;
import java.util.Map;
import org.codehaus.spice.loggerstore.LoggerStore;
import org.codehaus.spice.loggerstore.stores.Log4JLoggerStore;
import org.w3c.dom.Element;
/**
* DOMLog4JLoggerStoreFactory is an implementation of LoggerStoreFactory
* for the Log4J Logger using a DOM configuration resource.
*
* @author <a href="mailto:mauro.talevi at aquilonia.org">Mauro Talevi</a>
* @author <a href="mailto:peter at realityforge.org">Peter Donald</a>
* @version $Revision: 1.1 $ $Date: 2003/11/19 18:22:44 $
*/
public class DOMLog4JLoggerStoreFactory
extends AbstractLoggerStoreFactory
{
/**
* Creates a LoggerStore from a given set of configuration parameters.
*
* @param config the Map of parameters for the configuration of the store
* @return the LoggerStore
* @throws Exception if unable to create the LoggerStore
*/
protected LoggerStore doCreateLoggerStore( final Map config )
throws Exception
{
final Element element = (Element)config.get( Element.class.getName() );
if( null != element )
{
return new Log4JLoggerStore( element );
}
final InputStream resource = getInputStream( config );
if( null != resource )
{
return new Log4JLoggerStore( resource );
}
return missingConfiguration();
}
}
1.1 spice/components/loggerstore/src/java/org/codehaus/spice/loggerstore/factories/ExcaliburLogKitLoggerStoreFactory.java
Index: ExcaliburLogKitLoggerStoreFactory.java
===================================================================
/*
* Copyright (C) The Spice Group. All rights reserved.
*
* This software is published under the terms of the Spice
* Software License version 1.1, a copy of which has been included
* with this distribution in the LICENSE.txt file.
*/
package org.codehaus.spice.loggerstore.factories;
import java.util.Map;
import org.apache.avalon.excalibur.logger.LogKitLoggerManager;
import org.apache.avalon.excalibur.logger.LoggerManager;
import org.codehaus.spice.loggerstore.LoggerStore;
/**
* ExcaliburLogKitLoggerStoreFactory specialises the LogKitLoggerStoreFactory
* to use the Excalibur LogKitLoggerManager.
*
* @author <a href="mailto:mauro.talevi at aquilonia.org">Mauro Talevi</a>
*/
public class ExcaliburLogKitLoggerStoreFactory
extends LogKitLoggerStoreFactory
{
/**
* Creates a LoggerStore from a given set of configuration parameters.
*
* @param config the Map of parameters for the configuration of the store
* @return the LoggerStore
* @throws Exception if unable to create the LoggerStore
*/
protected LoggerStore doCreateLoggerStore( final Map config )
throws Exception
{
final LoggerManager loggerManager = new LogKitLoggerManager();
config.put( LoggerManager.class.getName(), loggerManager );
return super.doCreateLoggerStore( config );
}
}
1.1 spice/components/loggerstore/src/java/org/codehaus/spice/loggerstore/factories/ConsoleLoggerStoreFactory.java
Index: ConsoleLoggerStoreFactory.java
===================================================================
/*
* Copyright (C) The Spice Group. All rights reserved.
*
* This software is published under the terms of the Spice
* Software License version 1.1, a copy of which has been included
* with this distribution in the LICENSE.txt file.
*/
package org.codehaus.spice.loggerstore.factories;
import java.util.Map;
import org.codehaus.spice.loggerstore.LoggerStore;
import org.codehaus.spice.loggerstore.stores.ConsoleLoggerStore;
import org.jcontainer.dna.impl.ConsoleLogger;
/**
* This is a basic factory for ConsoleLoggerStore.
*
* @author <a href="mailto:peter at realityforge.org">Peter Donald</a>
* @version $Revision: 1.1 $ $Date: 2003/11/19 18:22:44 $
*/
public class ConsoleLoggerStoreFactory
extends AbstractLoggerStoreFactory
{
/**
* Creates a LoggerStore from a given set of configuration parameters.
*
* @param config the Map of parameters for the configuration of the store
* @return the LoggerStore
* @throws Exception if unable to create the LoggerStore
*/
protected LoggerStore doCreateLoggerStore( final Map config )
throws Exception
{
final int level = ConsoleLogger.LEVEL_INFO;
return new ConsoleLoggerStore( level );
}
}
1.1 spice/components/loggerstore/src/java/org/codehaus/spice/loggerstore/factories/AbstractLoggerStoreFactory.java
Index: AbstractLoggerStoreFactory.java
===================================================================
/*
* Copyright (C) The Spice Group. All rights reserved.
*
* This software is published under the terms of the Spice
* Software License version 1.1, a copy of which has been included
* with this distribution in the LICENSE.txt file.
*/
package org.codehaus.spice.loggerstore.factories;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.net.URL;
import java.util.Map;
import org.codehaus.spice.loggerstore.LoggerStore;
import org.codehaus.spice.loggerstore.LoggerStoreFactory;
import org.jcontainer.dna.AbstractLogEnabled;
/**
* The abstract class that makes it easy to create LoggerStoreFactory
* implementations.
*
* @author <a href="mailto:peter at realityforge.org">Peter Donald</a>
* @author <a href="mailto:mauro.talevi at aquilonia.org">Mauro Talevi</a>
* @version $Revision: 1.1 $ $Date: 2003/11/19 18:22:44 $
*/
public abstract class AbstractLoggerStoreFactory
extends AbstractLogEnabled
implements LoggerStoreFactory
{
/**
* Creates a LoggerStore from a given set of configuration parameters.
* The configuration map contains entrys specific to the
* concrete implementation.
*
* @param config the parameter map to configuration of the store
* @return the LoggerStore
* @throws Exception if unable to create the LoggerStore
*/
public LoggerStore createLoggerStore( final Map config )
throws Exception
{
final LoggerStore loggerStore = doCreateLoggerStore( config );
setupLogger( loggerStore );
return loggerStore;
}
protected abstract LoggerStore doCreateLoggerStore( Map config )
throws Exception;
/**
* Utility method to throw exception indicating input data
* was invalid.
*
* @return never returns
* @throws Exception indicating input data was invalid
*/
protected LoggerStore missingConfiguration()
throws Exception
{
throw new Exception( "Invalid configuration" );
}
/**
* A utility method to retrieve a InputStream from input map.
* It will systematically go through the following steps to
* attempt to locate the InputStream stopping at success.
*
* <ul>
* <li>Lookup LoggerStoreFactory.URL_LOCATION for
* string defining URL location of input configuration.</li>
* <li>Lookup java.net.URL for URL object defining URL location
* of input configuration.</li>
* <li>Lookup LoggerStoreFactory.FILE_LOCATION for
* string defining File location of input configuration.</li>
* <li>Lookup java.io.File for File object defining File location
* of input configuration.</li>
* <li>Lookup java.io.InputStream for InputStream object.</li>
* </ul>
*
* @param config the input map
* @return the InputStream or null if no stream present
* @throws Exception if there was a problem aquiring stream
*/
protected InputStream getInputStream( final Map config )
throws Exception
{
final String urlLocation = (String)config.get( URL_LOCATION );
URL url = null;
if( null != urlLocation )
{
url = new URL( urlLocation );
}
if( null == url )
{
url = (URL)config.get( URL.class.getName() );
}
if( null != url )
{
return url.openStream();
}
final String fileLocation = (String)config.get( FILE_LOCATION );
File file = null;
if( null != fileLocation )
{
file = new File( fileLocation );
}
if( null == file )
{
file = (File)config.get( File.class.getName() );
}
if( null != file )
{
return new FileInputStream( file );
}
return (InputStream)config.get( InputStream.class.getName() );
}
}
1.1 spice/components/loggerstore/src/java/org/codehaus/spice/loggerstore/factories/PropertyLog4JLoggerStoreFactory.java
Index: PropertyLog4JLoggerStoreFactory.java
===================================================================
/*
* Copyright (C) The Spice Group. All rights reserved.
*
* This software is published under the terms of the Spice
* Software License version 1.1, a copy of which has been included
* with this distribution in the LICENSE.txt file.
*/
package org.codehaus.spice.loggerstore.factories;
import java.io.InputStream;
import java.util.Map;
import java.util.Properties;
import org.codehaus.spice.loggerstore.LoggerStore;
import org.codehaus.spice.loggerstore.stores.Log4JLoggerStore;
/**
* PropertyLog4JLoggerStoreFactory is an implementation of LoggerStoreFactory
* for the Log4J Logger using a property configuration resource.
*
* @author <a href="mailto:mauro.talevi at aquilonia.org">Mauro Talevi</a>
* @author <a href="mailto:peter at realityforge.org">Peter Donald</a>
* @version $Revision: 1.1 $ $Date: 2003/11/19 18:22:44 $
*/
public class PropertyLog4JLoggerStoreFactory
extends AbstractLoggerStoreFactory
{
/**
* Creates a LoggerStore from a given set of configuration parameters.
*
* @param config the Map of parameters for the configuration of the store
* @return the LoggerStore
* @throws Exception if unable to create the LoggerStore
*/
protected LoggerStore doCreateLoggerStore( final Map config )
throws Exception
{
final Properties properties = (Properties)config.get( Properties.class.getName() );
if( null != properties )
{
return new Log4JLoggerStore( properties );
}
final InputStream resource = getInputStream( config );
if( null != resource )
{
return new Log4JLoggerStore( createPropertiesFromStream( resource ) );
}
return missingConfiguration();
}
private Properties createPropertiesFromStream( final InputStream resource )
throws Exception
{
final Properties properties = new Properties();
properties.load( resource );
return properties;
}
}
1.6 +2 -2 spice/components/loggerstore/src/test/META-INF/spice/loggerstore.properties
Index: loggerstore.properties
===================================================================
RCS file: /scm/cvs/spice/components/loggerstore/src/test/META-INF/spice/loggerstore.properties,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- loggerstore.properties 18 Oct 2003 09:14:30 -0000 1.5
+++ loggerstore.properties 19 Nov 2003 18:22:44 -0000 1.6
@@ -1,4 +1,4 @@
#Use the Log4J factory and use the log4j.properites file
-org.jcomponent.loggerstore.factory=org.jcomponent.loggerstore.factories.PropertyLog4JLoggerStoreFactory
-org.jcomponent.loggerstore.file=org/jcomponent/loggerstore/log4j.properties
+org.codehaus.spice.loggerstore.factory=org.codehaus.spice.loggerstore.factories.PropertyLog4JLoggerStoreFactory
+org.codehaus.spice.loggerstore.file=org/codehaus/spice/loggerstore/log4j.properties
1.1 spice/components/loggerstore/src/java/org/codehaus/spice/loggerstore/LoggerStore.java
Index: LoggerStore.java
===================================================================
/*
* Copyright (C) The Spice Group. All rights reserved.
*
* This software is published under the terms of the Spice
* Software License version 1.1, a copy of which has been included
* with this distribution in the LICENSE.txt file.
*/
package org.codehaus.spice.loggerstore;
import org.jcontainer.dna.Logger;
/**
* <p>LoggerStore represents the logging hierarchy for a Logger,
* as defined by its configuration.</p>
* <p>The LoggerStore has an associated LoggerStoreFactory which also
* acts as a configurator for the Logger.</p>
* <p>Whenever an application has finished using the LoggerStore it will call
* the close() method indicating that the logger hierarchy should also be shutdown. </p>
*
* @author <a href="mailto:mauro.talevi at aquilonia.org">Mauro Talevi</a>
* @author <a href="mailto:peter at realityforge.org">Peter Donald</a>
*/
public interface LoggerStore
{
/**
* Retrieves the root Logger from the store.
*
* @return the Logger
* @throws Exception if unable to retrieve Logger
*/
Logger getLogger()
throws Exception;
/**
* Retrieves a Logger hierarchy from the store for a given category name.
*
* @param categoryName the name of the logger category.
* @return the Logger
* @throws Exception if unable to retrieve Logger
*/
Logger getLogger( String categoryName )
throws Exception;
/**
* Closes the LoggerStore and shuts down the logger hierarchy.
*/
void close();
}
1.1 spice/components/loggerstore/src/java/org/codehaus/spice/loggerstore/LoggerStoreFactory.java
Index: LoggerStoreFactory.java
===================================================================
/*
* Copyright (C) The Spice Group. All rights reserved.
*
* This software is published under the terms of the Spice
* Software License version 1.1, a copy of which has been included
* with this distribution in the LICENSE.txt file.
*/
package org.codehaus.spice.loggerstore;
import java.util.Map;
/**
* <p>LoggerStoreFactory is a factory interface for LoggerStore instances.
* There is a factory implementation for each specific logger implementation
* (LogKit, Log4J, JDK14).
*
* <p>The factory also acts a configurator,
* handling the specific way in which a logger is configured.
* The LoggerStore is configured via a map of parameters passed in the
* create method. LoggerStoreFactory defines the keys used to retrieve
* the elements of the map.</p>
*
* @author <a href="mailto:mauro.talevi at aquilonia.org">Mauro Talevi</a>
* @author <a href="mailto:peter at realityforge.org">Peter Donald</a>
* @version $Revision: 1.1 $ $Date: 2003/11/19 18:22:44 $
*/
public interface LoggerStoreFactory
{
/**
* The URL key. Used to define the URL where the configuration
* for LoggerStore can be found.
*/
String URL_LOCATION = "org.codehaus.spice.loggerstore.url";
/**
* The URL key. Used to define the URL where the configuration
* for LoggerStore can be found.
*/
String FILE_LOCATION = "org.codehaus.spice.loggerstore.file";
/**
* Creates a LoggerStore from a given set of configuration parameters.
*
* @param config the Map of parameters for the configuration of the store
* @return the LoggerStore
* @throws Exception if unable to create the LoggerStore
*/
LoggerStore createLoggerStore( Map config )
throws Exception;
}
1.1 spice/components/loggerstore/src/java/org/codehaus/spice/loggerstore/Configurator.java
Index: Configurator.java
===================================================================
/*
* Copyright (C) The Spice Group. All rights reserved.
*
* This software is published under the terms of the Spice
* Software License version 1.1, a copy of which has been included
* with this distribution in the LICENSE.txt file.
*/
package org.codehaus.spice.loggerstore;
import java.io.InputStream;
import java.util.HashMap;
import org.codehaus.spice.loggerstore.factories.DOMLog4JLoggerStoreFactory;
import org.codehaus.spice.loggerstore.factories.ExcaliburLogKitLoggerStoreFactory;
import org.codehaus.spice.loggerstore.factories.InitialLoggerStoreFactory;
import org.codehaus.spice.loggerstore.factories.Jdk14LoggerStoreFactory;
import org.codehaus.spice.loggerstore.factories.PropertyLog4JLoggerStoreFactory;
import org.codehaus.spice.loggerstore.factories.SimpleLogKitLoggerStoreFactory;
/**
* Configurator is a collection of utility methods to create and configure
* LoggerStore objects of different types using configuration resources.
* LogKit, Log4J and JDK14 Loggers are supported.
* In the case of Log4J, both DOM and Property configuration types are supported.
*
* @author <a href="mailto:mauro.talevi at aquilonia.org">Mauro Talevi</a>
*/
public class Configurator
{
/**
* Constant used to define Log4J type with DOMConfigurator
*/
public static final String LOG4J_DOM = "log4j-dom";
/**
* Constant used to define Log4J type with PropertyConfigurator
*/
public static final String LOG4J_PROPERTY = "log4j-property";
/**
* Constant used to define LogKit type with Excalibur configuration
*/
public static final String LOGKIT_EXCALIBUR = "logkit-excalibur";
/**
* Constant used to define LogKit type with Simple configuration
*/
public static final String LOGKIT_SIMPLE = "logkit-simple";
/**
* Constant used to define JDK14 type
*/
public static final String JDK14 = "jdk14";
/**
* Create and configure a {@link LoggerStore} from a specified
* configuration resource.
*
* @param configuratorType the type of the configurator
* @param resource the String encoding the path of the configuration resource
* @return the configured LoggerStore
* @throws Exception if unable to create the LoggerStore
*/
public static LoggerStore createLoggerStore( final String configuratorType,
final String resource )
throws Exception
{
final InitialLoggerStoreFactory factory = new InitialLoggerStoreFactory();
final HashMap data = new HashMap();
data.put( InitialLoggerStoreFactory.INITIAL_FACTORY, getFactoryClassName( configuratorType ) );
data.put( LoggerStoreFactory.FILE_LOCATION, resource );
return factory.createLoggerStore( data );
}
/**
* Create and configure a {@link LoggerStore} from a specified
* configuration resource.
*
* @param configuratorType the type of the configurator
* @param resource the InputStream of the configuration resource
* @return the configured LoggerStore
* @throws Exception if unable to create the LoggerStore
*/
public static LoggerStore createLoggerStore( final String configuratorType,
final InputStream resource )
throws Exception
{
final InitialLoggerStoreFactory factory = new InitialLoggerStoreFactory();
final HashMap data = new HashMap();
data.put( InitialLoggerStoreFactory.INITIAL_FACTORY, getFactoryClassName( configuratorType ) );
data.put( InputStream.class.getName(), resource );
return factory.createLoggerStore( data );
}
/**
* Get the Factory class name of the LoggerStoreFactory that corresponds
* to specified type of Logger.
*
* @param type the type of Configurator
*/
private static String getFactoryClassName( final String type )
{
if( LOG4J_DOM.equals( type ) )
{
return DOMLog4JLoggerStoreFactory.class.getName();
}
else if( LOG4J_PROPERTY.equals( type ) )
{
return PropertyLog4JLoggerStoreFactory.class.getName();
}
else if( LOGKIT_EXCALIBUR.equals( type ) )
{
return ExcaliburLogKitLoggerStoreFactory.class.getName();
}
else if( LOGKIT_SIMPLE.equals( type ) )
{
return SimpleLogKitLoggerStoreFactory.class.getName();
}
else if( JDK14.equals( type ) )
{
return Jdk14LoggerStoreFactory.class.getName();
}
else
{
final String message = "Unknown type " + type;
throw new IllegalArgumentException( message );
}
}
}
1.22 +2 -2 spice/components/loggerstore/project.xml
Index: project.xml
===================================================================
RCS file: /scm/cvs/spice/components/loggerstore/project.xml,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- project.xml 19 Nov 2003 17:38:34 -0000 1.21
+++ project.xml 19 Nov 2003 18:22:44 -0000 1.22
@@ -4,8 +4,8 @@
<name>LoggerStore</name>
<id>spice-loggerstore</id>
<gumpRepositoryId>components</gumpRepositoryId>
- <package>org.jcomponent.loggerstore</package>
- <currentVersion>1.0-b2</currentVersion>
+ <package>org.codehaus.spice.loggerstore</package>
+ <currentVersion>1.0-b3</currentVersion>
<inceptionYear>2003</inceptionYear>
<shortDescription>Component for storing a set of DNA Loggers.</shortDescription>
1.4 +7 -7 spice/components/loggerstore/xdocs/configuration.xml
Index: configuration.xml
===================================================================
RCS file: /scm/cvs/spice/components/loggerstore/xdocs/configuration.xml,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- configuration.xml 18 Oct 2003 11:52:22 -0000 1.3
+++ configuration.xml 19 Nov 2003 18:22:44 -0000 1.4
@@ -44,17 +44,17 @@
The loggerstore.properties file contains the LoggerStore factory implementation class name and the
path the the configuration resource. For example:
<source>
-org.jcomponent.loggerstore.factory=org.jcomponent.loggerstore.factories.ExcaliburLogKitLoggerStoreFactory
-org.jcomponent.loggerstore.file=/path/to/logconfig.xml
+org.codehaus.spice.loggerstore.factory=org.codehaus.spice.loggerstore.factories.ExcaliburLogKitLoggerStoreFactory
+org.codehaus.spice.loggerstore.file=/path/to/logconfig.xml
</source>
</p>
<p>The possible factory classes are:
<ul>
- <li>org.jcomponent.loggerstore.factories.ExcaliburLogKitLoggerStoreFactory</li>
- <li>org.jcomponent.loggerstore.factories.SimpleLogKitLoggerStoreFactory</li>
- <li>org.jcomponent.loggerstore.factories.DOMLog4JLoggerStoreFactory</li>
- <li>org.jcomponent.loggerstore.factories.PropertyLog4JLoggerStoreFactory</li>
- <li>org.jcomponent.loggerstore.factories.JDK14LoggerStoreFactory</li>
+ <li>org.codehaus.spice.loggerstore.factories.ExcaliburLogKitLoggerStoreFactory</li>
+ <li>org.codehaus.spice.loggerstore.factories.SimpleLogKitLoggerStoreFactory</li>
+ <li>org.codehaus.spice.loggerstore.factories.DOMLog4JLoggerStoreFactory</li>
+ <li>org.codehaus.spice.loggerstore.factories.PropertyLog4JLoggerStoreFactory</li>
+ <li>org.codehaus.spice.loggerstore.factories.JDK14LoggerStoreFactory</li>
</ul>
</p>
</section>