mcconnell 2002/11/29 05:22:20 Added: assembly/src/java/org/apache/avalon/assembly/logging TargetProvider.java TargetDescriptor.java package.html LoggingManager.java LoggingDescriptor.java LoggerException.java FileTargetProvider.java DefaultLoggingManager.java Log: Seperation of the logging sub-system. Revision Changes Path 1.1 avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/logging/TargetProvider.java Index: TargetProvider.java =================================================================== /* ============================================================================ The Apache Software License, Version 1.1 ============================================================================ Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved. Redistribution and use in source and binary forms, with or without modifica- tion, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The end-user documentation included with the redistribution, if any, must include the following acknowledgment: "This product includes software developed by the Apache Software Foundation (http://www.apache.org/)." Alternately, this acknowledgment may appear in the software itself, if and wherever such third-party acknowledgments normally appear. 4. The names "Jakarta", "Apache Avalon", "Avalon Framework" and "Apache Software Foundation" must not be used to endorse or promote products derived from this software without prior written permission. For written permission, please contact [EMAIL PROTECTED] 5. Products derived from this software may not be called "Apache", nor may "Apache" appear in their name, without prior written permission of the Apache Software Foundation. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. This software consists of voluntary contributions made by many individuals on behalf of the Apache Software Foundation. For more information on the Apache Software Foundation, please see <http://www.apache.org/>. */ package org.apache.avalon.assembly.logging; import java.io.Serializable; /** * Abstract logging target provider type. This is an empty abstract class from * all logging providers must inherit. * * @author <a href="mailto:[EMAIL PROTECTED]">Avalon Development Team</a> * @version $Revision: 1.1 $ $Date: 2002/11/29 13:22:20 $ */ public abstract class TargetProvider implements Serializable { } 1.1 avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/logging/TargetDescriptor.java Index: TargetDescriptor.java =================================================================== /* ============================================================================ The Apache Software License, Version 1.1 ============================================================================ Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved. Redistribution and use in source and binary forms, with or without modifica- tion, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The end-user documentation included with the redistribution, if any, must include the following acknowledgment: "This product includes software developed by the Apache Software Foundation (http://www.apache.org/)." Alternately, this acknowledgment may appear in the software itself, if and wherever such third-party acknowledgments normally appear. 4. The names "Jakarta", "Apache Avalon", "Avalon Framework" and "Apache Software Foundation" must not be used to endorse or promote products derived from this software without prior written permission. For written permission, please contact [EMAIL PROTECTED] 5. Products derived from this software may not be called "Apache", nor may "Apache" appear in their name, without prior written permission of the Apache Software Foundation. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. This software consists of voluntary contributions made by many individuals on behalf of the Apache Software Foundation. For more information on the Apache Software Foundation, please see <http://www.apache.org/>. */ package org.apache.avalon.assembly.logging; import java.io.Serializable; /** * A logging target descriptor. * * <p><b>XML</b></p> * A logging target declares target name and a logging mechanism.</p> * * <pre> * <target name="<font color="darkred">kernel</font>"> * <file location="<font color="darkred">kernel.log</font>" /> * </target> * </pre> * * @author <a href="mailto:[EMAIL PROTECTED]">Avalon Development Team</a> * @version $Revision: 1.1 $ $Date: 2002/11/29 13:22:20 $ */ public final class TargetDescriptor implements Serializable { /** * The target name. */ private final String m_name; /** * The target provider descriptor. */ private final TargetProvider m_provider; /** * Create a LoggingDescriptor instance. * * @param name the target name * @param provider the target provider description */ public TargetDescriptor( final String name, final TargetProvider provider ) { m_name = name; m_provider = provider; } /** * Return the target name. * * @return the target name. */ public String getName() { return m_name; } /** * Return the target provider descriptor * * @return the provider descriptor */ public TargetProvider getProvider() { return m_provider; } } 1.1 avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/logging/package.html Index: package.html =================================================================== <body> <p> The <code>logging</code> package contains the {@link org.apache.avalon.assembly.logging.DefaultLoggerManager} which is an initial bootstrap logging mananager that uses mata inforatrion about logging targets and catagories. Rhis class is subject to refactoring to bring in into a component model to enable easy specialization and/or replacement. </p> </body> 1.1 avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/logging/LoggingManager.java Index: LoggingManager.java =================================================================== /* ============================================================================ The Apache Software License, Version 1.1 ============================================================================ Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved. Redistribution and use in source and binary forms, with or without modifica- tion, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The end-user documentation included with the redistribution, if any, must include the following acknowledgment: "This product includes software developed by the Apache Software Foundation (http://www.apache.org/)." Alternately, this acknowledgment may appear in the software itself, if and wherever such third-party acknowledgments normally appear. 4. The names "Jakarta", "Apache Avalon", "Avalon Framework" and "Apache Software Foundation" must not be used to endorse or promote products derived from this software without prior written permission. For written permission, please contact [EMAIL PROTECTED] 5. Products derived from this software may not be called "Apache", nor may "Apache" appear in their name, without prior written permission of the Apache Software Foundation. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. This software consists of voluntary contributions made by many individuals on behalf of the Apache Software Foundation. For more information on the Apache Software Foundation, please see <http://www.apache.org/>. */ package org.apache.avalon.assembly.logging; import org.apache.avalon.framework.logger.Logger; import org.apache.avalon.excalibur.logger.LoggerManager; import org.apache.avalon.meta.model.LoggingDirective; import org.apache.avalon.meta.model.Category; /** * A <code>LoggerManager</code> that supports the management of a logging hierarchy. * @author <a href="mailto:[EMAIL PROTECTED]">Avalon Development Team</a> */ public interface LoggingManager extends LoggerManager { /** * Add a set of category entries using the supplied categories descriptor. * @param descriptor a set of category descriptors to be added under the path */ public void addCategories( LoggingDirective descriptor ); /** * Add a set of category entries relative to the supplied base category * path, using the supplied descriptor as the definition of subcategories. * @param path the category base path * @param descriptor a set of category descriptors to be added under * the base path */ public void addCategories( String path, LoggingDirective descriptor ); /** * Create a logging channel configured with the supplied category path, * priority and target. * * @param name logging category path * @param target the logging target to assign the channel to * @param priority the priority level to assign to the channel * @return the logging channel * @throws Exception if an error occurs */ public Logger getLoggerForCategory( final String name, String target, String priority ) throws Exception; /** * Configure Logging channel based on the description supplied in a * category descriptor. * * @param category defintion of the channel category, priority and target * @return the logging channel * @throws Exception if an error occurs */ public Logger getLoggerForCategory( final Category category ) throws Exception; //=============================================================== // LoggerManager //=============================================================== /** * Return the Logger for the specified category. * @param category the category path * @return the logging channel */ public Logger getLoggerForCategory( final String category ); /** * Return the default Logger. This is the same * as getting the Logger for the "" category. * @return the default logging channel */ public Logger getDefaultLogger(); } 1.1 avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/logging/LoggingDescriptor.java Index: LoggingDescriptor.java =================================================================== /* ============================================================================ The Apache Software License, Version 1.1 ============================================================================ Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved. Redistribution and use in source and binary forms, with or without modifica- tion, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The end-user documentation included with the redistribution, if any, must include the following acknowledgment: "This product includes software developed by the Apache Software Foundation (http://www.apache.org/)." Alternately, this acknowledgment may appear in the software itself, if and wherever such third-party acknowledgments normally appear. 4. The names "Jakarta", "Apache Avalon", "Avalon Framework" and "Apache Software Foundation" must not be used to endorse or promote products derived from this software without prior written permission. For written permission, please contact [EMAIL PROTECTED] 5. Products derived from this software may not be called "Apache", nor may "Apache" appear in their name, without prior written permission of the Apache Software Foundation. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. This software consists of voluntary contributions made by many individuals on behalf of the Apache Software Foundation. For more information on the Apache Software Foundation, please see <http://www.apache.org/>. */ package org.apache.avalon.assembly.logging; import org.apache.avalon.meta.model.Category; /** * Description of a top level logging system. * * <p><b>XML</b></p> * <p>A logging element declares the top level defaults for priority and target name, a set of * targets to which logging events shall be directed. * The logging element declares the application wide default logging priority. * A target element enables defintion of a logging file to which log entries will * be directed. The target name attribute is the name referenced by category elements * defined within the loggers element. The priority attribute may container one of the values * <code>DEBUG</code>, <code>INFO</code>, <code>WARN</code> or <code>ERROR</code>. * The target must contain a single file element with the attribute <code>location</code> * the corresponds to the name of the logging file.</p> * * <pre> * <font color="gray"><i><!-- * Definition of a logging system. * --></i></font> * * <logging name="" priority="<font color="darkred">INFO</font>" target="<font color="darkred">kernel</font>"> * <category name="logging" priority="<font color="darkred">WARN</font>"/> * <target name="<font color="darkred">kernel</font>"> * <file location="<font color="darkred">kernel.log</font>" /> * </target> * </logging> * </pre> * * @see TargetDescriptor * @author <a href="mailto:[EMAIL PROTECTED]">Avalon Development Team</a> * @version $Revision: 1.1 $ $Date: 2002/11/29 13:22:20 $ */ public final class LoggingDescriptor extends Category { /** * The dependencies keyed by role name. */ private final TargetDescriptor[] m_targets; /** * The bootstrap logging category. */ private final Category m_bootstrap; /** * Create a LoggingDescriptor instance. */ public LoggingDescriptor() { this( "", null, null, new TargetDescriptor[ 0 ], new Category( "logging" ) ); } /** * Create a LoggingDescriptor instance. * * @param root the root logger category name * @param priority the default logging priority * @param target the default logging target * @param targets the set of logging targets * @param bootstrap the bootstrap category to use to log mesages * from the logging system */ public LoggingDescriptor( final String root, final String priority, final String target, final TargetDescriptor[] targets, final Category bootstrap ) { super( root, priority, target ); m_targets = targets; m_bootstrap = bootstrap; } /** * Return the set of logging target descriptors. * * @return the target descriptors */ public TargetDescriptor[] getTargetDescriptors() { return m_targets; } /** * Return the bootstrap logging category to which the logging manager will * log information about its own activities. * * @return the category */ public Category getBootstrapCategory() { return m_bootstrap; } } 1.1 avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/logging/LoggerException.java Index: LoggerException.java =================================================================== /* ============================================================================ The Apache Software License, Version 1.1 ============================================================================ Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved. Redistribution and use in source and binary forms, with or without modifica- tion, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The end-user documentation included with the redistribution, if any, must include the following acknowledgment: "This product includes software developed by the Apache Software Foundation (http://www.apache.org/)." Alternately, this acknowledgment may appear in the software itself, if and wherever such third-party acknowledgments normally appear. 4. The names "Jakarta", "Apache Avalon", "Avalon Framework" and "Apache Software Foundation" must not be used to endorse or promote products derived from this software without prior written permission. For written permission, please contact [EMAIL PROTECTED] 5. Products derived from this software may not be called "Apache", nor may "Apache" appear in their name, without prior written permission of the Apache Software Foundation. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. This software consists of voluntary contributions made by many individuals on behalf of the Apache Software Foundation. For more information on the Apache Software Foundation, please see <http://www.apache.org/>. */ package org.apache.avalon.assembly.logging; import org.apache.avalon.framework.CascadingException; /** * Exception to indicate that there was a logging management related error. * * @author <a href="mailto:[EMAIL PROTECTED]">Avalon Development Team</a> * @version $Revision: 1.1 $ $Date: 2002/11/29 13:22:20 $ */ public class LoggerException extends CascadingException { /** * Construct a new <code>LoggerException</code> instance. * * @param message The detail message for this exception. */ public LoggerException( final String message ) { this( message, null ); } /** * Construct a new <code>LoggerException</code> instance. * * @param message The detail message for this exception. * @param throwable the root cause of the exception */ public LoggerException( final String message, final Throwable throwable ) { super( message, throwable ); } } 1.1 avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/logging/FileTargetProvider.java Index: FileTargetProvider.java =================================================================== /* ============================================================================ The Apache Software License, Version 1.1 ============================================================================ Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved. Redistribution and use in source and binary forms, with or without modifica- tion, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The end-user documentation included with the redistribution, if any, must include the following acknowledgment: "This product includes software developed by the Apache Software Foundation (http://www.apache.org/)." Alternately, this acknowledgment may appear in the software itself, if and wherever such third-party acknowledgments normally appear. 4. The names "Jakarta", "Apache Avalon", "Avalon Framework" and "Apache Software Foundation" must not be used to endorse or promote products derived from this software without prior written permission. For written permission, please contact [EMAIL PROTECTED] 5. Products derived from this software may not be called "Apache", nor may "Apache" appear in their name, without prior written permission of the Apache Software Foundation. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. This software consists of voluntary contributions made by many individuals on behalf of the Apache Software Foundation. For more information on the Apache Software Foundation, please see <http://www.apache.org/>. */ package org.apache.avalon.assembly.logging; /** * File target provider descriptor declares the criteria for creation of * an file based logging target. * * <p><b>XML</b></p> * <p>A file target element may be contained within a target element to declare * the target as a file based logging sink.</p> * <pre> * <font color="gray"><target name="kernel"></font> * <file location="<font color="darkred">kernel.log</font>" /> * <font color="gray"></target></font> * </pre> * * @see TargetDescriptor * @author <a href="mailto:[EMAIL PROTECTED]">Avalon Development Team</a> * @version $Revision: 1.1 $ $Date: 2002/11/29 13:22:20 $ */ public class FileTargetProvider extends TargetProvider { private final String m_location; /** * Creation of a new file target. * @param location the filename of the logging destination */ public FileTargetProvider( final String location ) { m_location = location; } /** * Return the filename of the logging target. * @return the filename */ public String getLocation() { return m_location; } } 1.1 avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/logging/DefaultLoggingManager.java Index: DefaultLoggingManager.java =================================================================== /* ============================================================================ The Apache Software License, Version 1.1 ============================================================================ Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved. Redistribution and use in source and binary forms, with or without modifica- tion, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The end-user documentation included with the redistribution, if any, must include the following acknowledgment: "This product includes software developed by the Apache Software Foundation (http://www.apache.org/)." Alternately, this acknowledgment may appear in the software itself, if and wherever such third-party acknowledgments normally appear. 4. The names "Jakarta", "Apache Avalon", "Avalon Framework" and "Apache Software Foundation" must not be used to endorse or promote products derived from this software without prior written permission. For written permission, please contact [EMAIL PROTECTED] 5. Products derived from this software may not be called "Apache", nor may "Apache" appear in their name, without prior written permission of the Apache Software Foundation. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. This software consists of voluntary contributions made by many individuals on behalf of the Apache Software Foundation. For more information on the Apache Software Foundation, please see <http://www.apache.org/>. */ package org.apache.avalon.assembly.logging; import java.io.File; import java.io.IOException; import java.util.HashMap; 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; import org.apache.log.output.io.StreamTarget; import org.apache.avalon.framework.logger.AvalonFormatter; import org.apache.avalon.framework.logger.LogKitLogger; 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.meta.model.LoggingDirective; import org.apache.avalon.meta.model.Category; /** * A <code>LoggerManager</code> interface declares operation supporting * the management of a logging hierarchy. * * @author <a href="mailto:[EMAIL PROTECTED]">Avalon Development Team</a> */ public class DefaultLoggingManager implements LoggingManager { /** * The default logging priority value. */ public static final String DEFAULT_PRIORITY = "INFO"; /** * The default logging target name. */ public static final String DEFAULT_TARGET = "default"; private static final Resources REZ = ResourceManager.getPackageResources( DefaultLoggingManager.class ); private static final String DEFAULT_FORMAT = "[%7.7{priority}] (%{category}): %{message}\\n%{throwable}"; /** * Base directory of file targets. */ private File m_baseDirectory; /** * log hierarchy. */ private Hierarchy m_logHierarchy; /** * default logger */ private org.apache.avalon.framework.logger.Logger m_logger; /** * default logger target */ private StreamTarget m_stream; private final HashMap m_targets = new HashMap(); private DefaultLoggingManager m_parent; private String m_category; //=============================================================== // constructor //=============================================================== /** * Creation of a new LoggerManager. * @param base the base directory * @exception Exception is an error occurs */ public DefaultLoggingManager( File base ) throws Exception { this( new LoggingDescriptor( "", null, null, new TargetDescriptor[ 0 ], new Category( "logging", "DEBUG", null ) ), base ); } /** * Creation of a new LoggerManager. * @param descriptor the logging system description * @param base the base directory * @exception Exception is an error occurs */ public DefaultLoggingManager( final LoggingDescriptor descriptor, File base ) throws Exception { // // setup the hierarchy, default logging target, and default priority // m_stream = new StreamTarget( System.out, new AvalonFormatter( DEFAULT_FORMAT ) ); m_baseDirectory = base; m_logHierarchy = new Hierarchy(); getHierarchy().setDefaultLogTarget( m_stream ); m_targets.put( DEFAULT_TARGET, m_stream ); if( descriptor.getPriority() != null ) { getHierarchy().setDefaultPriority( Priority.getPriorityForName( descriptor.getPriority() ) ); } else { getHierarchy().setDefaultPriority( Priority.getPriorityForName( DEFAULT_PRIORITY ) ); } // // setup the bootstrap logging category // Category bootstrap = descriptor.getBootstrapCategory(); m_logger = new LogKitLogger( addCategory( bootstrap.getName(), bootstrap.getPriority(), bootstrap.getTarget(), false ) ); // // build targets based on the information contained in the descriptor // TargetDescriptor[] targets = descriptor.getTargetDescriptors(); for( int i = 0; i < targets.length; i++ ) { addTarget( targets[ i ] ); } // // set the default target // String name = descriptor.getTarget(); if( name != null ) { LogTarget target = (LogTarget)m_targets.get( name ); if( target != null ) { getHierarchy().setDefaultLogTarget( target ); } else { throw new LoggerException( "Supplied default logging target: '" + name + "' does not exist." ); } } } /** * Add a set of category entries using the supplied categories descriptor. * @param descriptor a set of category descriptors to be added under the path */ public void addCategories( LoggingDirective descriptor ) { addCategories( "", descriptor ); } /** * Add a set of category entries relative to the supplied base category * path, using the supplied descriptor as the definition of subcategories. * @param path the category base path * @param descriptor a set of category descriptors to be added under * the base path */ public void addCategories( String path, LoggingDirective descriptor ) { addCategory( path, descriptor.getPriority(), descriptor.getTarget() ); Category[] categories = descriptor.getCategories(); for( int i = 0; i < categories.length; i++ ) { Category category = categories[ i ]; final String priority = category.getPriority(); final String target = category.getTarget(); if( path.equals( "" ) ) { addCategory( category.getName(), priority, target ); } else { addCategory( path + "." + category.getName(), priority, target ); } } } /** * Create a logging channel configured with the supplied category path, * priority and target. * * @param name logging category path * @param target the logging target to assign the channel to * @param priority the priority level to assign to the channel * @return the logging channel * @throws Exception if an error occurs */ public org.apache.avalon.framework.logger.Logger getLoggerForCategory( final String name, String target, String priority ) throws Exception { return new LogKitLogger( addCategory( name, target, priority ) ); } /** * Configure Logging channel based on the description supplied in a * category descriptor. * * @param category defintion of the channel category, priority and target * @return the logging channel * @throws Exception if an error occurs */ public org.apache.avalon.framework.logger.Logger getLoggerForCategory( final Category category ) throws Exception { return new LogKitLogger( addCategory( category.getName(), category.getPriority(), category.getTarget() ) ); } //=============================================================== // LoggerManager //=============================================================== /** * Return the Logger for the specified category. * @param category the category path * @return the logging channel */ public org.apache.avalon.framework.logger.Logger getLoggerForCategory( final String category ) { if( category == null ) { return new LogKitLogger( getHierarchy().getLoggerFor( "" ) ); } else { String cat; if( category.indexOf( "/" ) > -1 ) { cat = category.replace( '/', '.' ); if( cat.startsWith( "." ) ) { cat = cat.substring( 1 ); } } else { cat = category; } return new LogKitLogger( getHierarchy().getLoggerFor( cat ) ); } } /** * Return the default Logger. This is the same * as getting the Logger for the "" category. * @return the default logging channel */ public org.apache.avalon.framework.logger.Logger getDefaultLogger() { if( m_logger == null ) { m_logger = getLoggerForCategory( "" ); } return m_logger; } /** * Add a single category entries relative to the supplied base category * path, using the supplied category. * @param path the category base path * @param category a category descriptors to be added under the base path */ private Logger addCategory( String path, Category category ) { return addCategory( path, category.getPriority(), category.getTarget(), true ); } private Logger addCategory( String path, String priority, String target ) { return addCategory( path, priority, target, true ); } private Logger addCategory( String path, String priority, String target, boolean notify ) { final Logger logger = getHierarchy().getLoggerFor( path ); if( priority != null ) { final Priority priorityValue = Priority.getPriorityForName( priority ); if( !priorityValue.getName().equals( priority ) ) { final String message = REZ.getString( "unknown-priority", priority, path ); throw new IllegalArgumentException( message ); } logger.setPriority( priorityValue ); } if( target != null ) { if( !target.equals("default") ) { final LogTarget logTarget = (LogTarget)m_targets.get( target ); if( logTarget != null ) { logger.setLogTargets( new LogTarget[]{logTarget} ); } } } if( notify && getLogger().isInfoEnabled() ) { final String message = REZ.getString( "category-create", path, target, logger.getPriority() ); getLogger().info( message ); } return logger; } private void addTarget( TargetDescriptor target ) throws Exception { final String name = target.getName(); TargetProvider provider = target.getProvider(); if( provider instanceof FileTargetProvider ) { FileTargetProvider fileProvider = (FileTargetProvider)provider; String filename = fileProvider.getLocation(); final AvalonFormatter formatter = new AvalonFormatter( DEFAULT_FORMAT ); File file = new File( m_baseDirectory, filename ); try { FileTarget logTarget = new FileTarget( file.getAbsoluteFile(), false, formatter ); m_targets.put( name, logTarget ); } catch( final IOException ioe ) { final String message = REZ.getString( "target.nocreate", name, file, ioe.getMessage() ); throw new LoggerException( message, ioe ); } } else { final String error = "Unrecognized logging provider: " + provider.getClass().getName(); throw new IllegalArgumentException( error ); } } /** * Return the internal Logger. */ private org.apache.avalon.framework.logger.Logger getLogger() { return m_logger; } private Hierarchy getHierarchy() { if( m_parent != null ) { return m_parent.getHierarchy(); } return m_logHierarchy; } }
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>