donaldp 2002/10/23 00:18:47
Modified: logger build.xml default.properties
Added: logger/src/java/org/apache/avalon/excalibur/logger
SimpleLogKitManager.java
Log:
Integrate Phoenixs SImpleLogKitManager into Logger jar
Revision Changes Path
1.29 +4 -2 jakarta-avalon-excalibur/logger/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/logger/build.xml,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- build.xml 16 Oct 2002 16:37:02 -0000 1.28
+++ build.xml 23 Oct 2002 07:18:47 -0000 1.29
@@ -15,6 +15,7 @@
<pathelement location="${avalon-logkit.jar}"/> <!-- deprecated -->
<pathelement location="${logkit.jar}"/>
<pathelement location="${avalon-framework.jar}"/>
+ <pathelement location="${excalibur-i18n.jar}"/>
<pathelement location="${checkstyle.jar}"/>
<!-- Optional jars -->
@@ -114,6 +115,7 @@
<ant antfile="${depchecker.prefix}/depchecker.xml" target="checkCommon"/>
<ant antfile="${depchecker.prefix}/depchecker.xml" target="checkFramework"/>
<ant antfile="${depchecker.prefix}/depchecker.xml" target="checkLogkit"/>
+ <ant antfile="${depchecker.prefix}/depchecker.xml" target="checkI18n"/>
</target>
<target name="dependencies-test" depends="dist-jar, dependencies"
@@ -188,7 +190,7 @@
<target name="optional-warnings"
depends="jms-warn,sql-warn,mail-warn,log4j-warn,servlet-warn"
- description="Outputs warnings if some jars are missing from the environment">
+ description="Outputs warnings if some jars are missing from the environment">
</target>
<!-- Compiles the source code -->
@@ -489,7 +491,7 @@
<fileset dir="${build.docs}">
<include name="**"/>
</fileset>
- </copy>
+ </copy>
</target>
1.11 +4 -0 jakarta-avalon-excalibur/logger/default.properties
Index: default.properties
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/logger/default.properties,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- default.properties 23 Sep 2002 18:41:00 -0000 1.10
+++ default.properties 23 Oct 2002 07:18:47 -0000 1.11
@@ -62,6 +62,10 @@
excalibur-pool.lib=${excalibur-pool.home}
excalibur-pool.jar=${excalibur-pool.lib}/excalibur-pool-1.1.jar
+# ----- Excalibur i18n, version 1.0 or later -----
+excalibur-i18n.home=${basedir}/../i18n/dist
+excalibur-i18n.lib=${excalibur-i18n.home}
+excalibur-i18n.jar=${excalibur-i18n.lib}/excalibur-i18n-1.0.jar
# --------------------------------------------------
1.1
jakarta-avalon-excalibur/logger/src/java/org/apache/avalon/excalibur/logger/SimpleLogKitManager.java
Index: SimpleLogKitManager.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 java.io.File;
import java.io.IOException;
import java.util.HashMap;
import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.avalon.excalibur.logger.LoggerManager;
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.context.Context;
import org.apache.avalon.framework.context.ContextException;
import org.apache.avalon.framework.context.Contextualizable;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.logger.AvalonFormatter;
import org.apache.avalon.framework.logger.LogKitLogger;
import org.apache.log.Hierarchy;
import org.apache.log.LogTarget;
import org.apache.log.Logger;
import org.apache.log.Priority;
import org.apache.log.output.io.FileTarget;
/**
* A {@link LoggerManager} that supports the old <logs version="1.0"/>
* style logging configuration from
* <a href="http://jakarta.apache.org/avalon/phoenix">Phoenix</a>.
*
* @author <a href="mailto:colus@;isoft.co.kr">Eung-ju Park</a>
* @author <a href="mailto:peter at apache.org">Peter Donald</a>
*/
public class SimpleLogKitManager
extends AbstractLogEnabled
implements LoggerManager, Contextualizable, Configurable
{
private static final Resources REZ =
ResourceManager.getPackageResources( SimpleLogKitManager.class );
private static final String DEFAULT_FORMAT =
"%7.7{priority} %23.23{time:yyyy-MM-dd' 'HH:mm:ss.SSS} [%8.8{category}]
(%{context}): "
+ "%{message}\n%{throwable}";
///Base directory of applications working directory
private File m_baseDirectory;
/**
* Hierarchy of Application logging
*/
private final Hierarchy m_hierarchy = new Hierarchy();
/**
* The root logger in hierarchy.
*/
private final Logger m_logkitLogger = m_hierarchy.getLoggerFor( "" );
/**
* The root logger wrapped using AValons Logging Facade.
*/
private org.apache.avalon.framework.logger.Logger m_logger =
new LogKitLogger( m_logkitLogger );
/**
* Contextualize the manager. Requires that the "app.home" entry
* be set to a File object that points at the base directory for logs.
*
* @param context the context
* @throws ContextException if missing context entry
*/
public void contextualize( final Context context )
throws ContextException
{
m_baseDirectory = (File)context.get( "app.home" );
}
/**
* Interpret configuration to build loggers.
*
* @param configuration the configuration
* @throws ConfigurationException if malformed configuration
*/
public void configure( final Configuration configuration )
throws ConfigurationException
{
final Configuration[] targets = configuration.getChildren( "log-target" );
final HashMap targetSet = configureTargets( targets );
final Configuration[] categories = configuration.getChildren( "category" );
configureCategories( categories, targetSet );
}
/**
* Retrieve a logger by name.
*
* @param name the name of logger
* @return the specified Logger
*/
public org.apache.avalon.framework.logger.Logger
getLoggerForCategory( final String name )
{
return m_logger.getChildLogger( name );
}
/**
* Retrieve the root logger.
*
* @return the root Logger
*/
public org.apache.avalon.framework.logger.Logger getDefaultLogger()
{
return m_logger;
}
/**
* Configure a set of logtargets based on config data.
*
* @param targets the target configuration data
* @return a Map of target-name to target
* @throws ConfigurationException if an error occurs
*/
private HashMap configureTargets( final Configuration[] targets )
throws ConfigurationException
{
final HashMap targetSet = new HashMap();
for( int i = 0; i < targets.length; i++ )
{
final Configuration target = targets[ i ];
final String name = target.getAttribute( "name" );
String location = target.getAttribute( "location" ).trim();
final String format = target.getAttribute( "format", DEFAULT_FORMAT );
if( '/' == location.charAt( 0 ) )
{
location = location.substring( 1 );
}
final AvalonFormatter formatter = new AvalonFormatter( format );
//Specify output location for logging
final File file = new File( m_baseDirectory, location );
//Setup logtarget
FileTarget logTarget = null;
try
{
logTarget = new FileTarget( file.getAbsoluteFile(), true, formatter
);
}
catch( final IOException ioe )
{
final String message =
REZ.getString( "target.nocreate", name, file, ioe.getMessage() );
throw new ConfigurationException( message, ioe );
}
targetSet.put( name, logTarget );
}
return targetSet;
}
/**
* Configure Logging categories.
*
* @param categories configuration data for categories
* @param targets a hashmap containing the already existing taregt
* @throws ConfigurationException if an error occurs
*/
private void configureCategories( final Configuration[] categories, final
HashMap targets )
throws ConfigurationException
{
for( int i = 0; i < categories.length; i++ )
{
final Configuration category = categories[ i ];
final String name = category.getAttribute( "name", "" );
final String target = category.getAttribute( "target" );
final String priorityName = category.getAttribute( "priority" );
final Logger logger =
m_logkitLogger.getChildLogger( name );
final LogTarget logTarget = (LogTarget)targets.get( target );
if( null == target )
{
final String message = REZ.getString( "unknown-target", target, name
);
throw new ConfigurationException( message );
}
final Priority priority = Priority.getPriorityForName( priorityName );
if( !priority.getName().equals( priorityName ) )
{
final String message = REZ.getString( "unknown-priority",
priorityName, name );
throw new ConfigurationException( message );
}
if( getLogger().isDebugEnabled() )
{
final String message =
REZ.getString( "category-create", name, target, priorityName );
getLogger().debug( message );
}
if( name.equals( "" ) )
{
//TODO: Use m_logkitLogger instead
m_hierarchy.setDefaultPriority( priority );
m_hierarchy.setDefaultLogTarget( logTarget );
}
else
{
logger.setPriority( priority );
logger.setLogTargets( new LogTarget[]{logTarget} );
}
}
}
}
--
To unsubscribe, e-mail: <mailto:avalon-cvs-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-cvs-help@;jakarta.apache.org>