psmith 2003/06/24 01:24:57 Modified: src/java/org/apache/log4j/plugins Receiver.java PluginSkeleton.java PluginRegistry.java Plugin.java Added: src/java/org/apache/log4j/plugins Pauseable.java Log: moving to jakarta-log4j from jakarta-log4j-sandbox. Revision Changes Path 1.5 +39 -1 jakarta-log4j/src/java/org/apache/log4j/plugins/Receiver.java Index: Receiver.java =================================================================== RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/plugins/Receiver.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- Receiver.java 18 Mar 2003 13:33:30 -0000 1.4 +++ Receiver.java 24 Jun 2003 08:24:57 -0000 1.5 @@ -49,8 +49,10 @@ package org.apache.log4j.plugins; +import org.apache.log4j.Level; import org.apache.log4j.Logger; import org.apache.log4j.spi.LoggingEvent; +import org.apache.log4j.spi.Thresholdable; /** @@ -84,15 +86,51 @@ @author Mark Womack @author Ceki Gülcü + @author Paul Smith <[EMAIL PROTECTED]> @since 1.3 */ -public abstract class Receiver extends PluginSkeleton { +public abstract class Receiver extends PluginSkeleton implements Thresholdable { + protected Level thresholdLevel; + + /** + Sets the receiver theshold to the given level. + + @param level The threshold level events must equal or be greater + than before further processing can be done. */ + public void setThreshold(Level level) { + thresholdLevel = level; + } + + /** + Gets the current threshold setting of the receiver. + + @return Level The current threshold level of the receiver. */ + public Level getThreshold() { + return thresholdLevel; + } + + /** + Returns true if the given level is equals or greater than the current + threshold value of the receiver. + + @param level The level to test against the receiver threshold. + @return boolean True if level is equal or greater than the + receiver threshold. */ + public boolean isAsSevereAsThreshold(Level level) { + return ((thresholdLevel == null) || level.isGreaterOrEqual(thresholdLevel)); + } + /** Posts the logging event to a logger in the configured logger repository. @param event the log event to post to the local log4j environment. */ public void doPost(LoggingEvent event) { + // if event does not meet threshold, exit now + if (!isAsSevereAsThreshold(event.getLevel())) { + return; + } + // get the "local" logger for this event from the // configured repository. Logger localLogger = 1.6 +11 -0 jakarta-log4j/src/java/org/apache/log4j/plugins/PluginSkeleton.java Index: PluginSkeleton.java =================================================================== RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/plugins/PluginSkeleton.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- PluginSkeleton.java 18 Mar 2003 13:33:30 -0000 1.5 +++ PluginSkeleton.java 24 Jun 2003 08:24:57 -0000 1.6 @@ -66,6 +66,7 @@ Contributors: Nicko Cadell @author Mark Womack + @author Paul Smith <[EMAIL PROTECTED]> @since 1.3 */ public abstract class PluginSkeleton implements Plugin { @@ -74,6 +75,7 @@ /** Repository this plugin is attached to. */ protected LoggerRepository repository; + protected boolean active; /** Gets the name of the plugin. @@ -107,4 +109,13 @@ public void setLoggerRepository(LoggerRepository repository) { this.repository = repository; } + + /** + * Returns whether this plugin is Active or not + * @return true/false + */ + public synchronized boolean isActive() { + return active; + } + } 1.6 +53 -0 jakarta-log4j/src/java/org/apache/log4j/plugins/PluginRegistry.java Index: PluginRegistry.java =================================================================== RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/plugins/PluginRegistry.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- PluginRegistry.java 18 Mar 2003 13:33:30 -0000 1.5 +++ PluginRegistry.java 24 Jun 2003 08:24:57 -0000 1.6 @@ -53,7 +53,11 @@ import org.apache.log4j.spi.LoggerRepository; import org.apache.log4j.spi.LoggerRepositoryEventListener; +import java.util.Collections; +import java.util.Map; import java.util.HashMap; +import java.util.List; +import java.util.ArrayList; import java.util.Iterator; @@ -144,6 +148,55 @@ } } + /** + Returns all the plugins for a given repository. + + @param repository the logger repository to get the plugins from. + @return List list of plugins from the repository. */ + public static List getPlugins(LoggerRepository repository) { + synchronized (repositoryMap) { + // get plugin map for repository + Map pluginMap = (Map) repositoryMap.get(repository); + if (pluginMap == null) { + return Collections.EMPTY_LIST; + } else { + List pluginList = new ArrayList(pluginMap.size()); + Iterator iter = pluginMap.values().iterator(); + while (iter.hasNext()) { + pluginList.add(iter.next()); + } + return pluginList; + } + } + } + + /** + Returns all the plugins for a given repository that are instances + of a certain class. + + @param repository the logger repository to get the plugins from. + @param pluginClass the class the plugin must implement to be selected. + @return List list of plugins from the repository. */ + public static List getPlugins(LoggerRepository repository, Class pluginClass) { + synchronized (repositoryMap) { + // get plugin map for repository + Map pluginMap = (Map) repositoryMap.get(repository); + if (pluginMap == null) { + return Collections.EMPTY_LIST; + } else { + List pluginList = new ArrayList(pluginMap.size()); + Iterator iter = pluginMap.values().iterator(); + while (iter.hasNext()) { + Object plugin = iter.next(); + if (pluginClass.isInstance(plugin)) { + pluginList.add(plugin); + } + } + return pluginList; + } + } + } + /** Stops a plugin by plugin object. 1.5 +2 -1 jakarta-log4j/src/java/org/apache/log4j/plugins/Plugin.java Index: Plugin.java =================================================================== RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/plugins/Plugin.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- Plugin.java 18 Mar 2003 13:33:30 -0000 1.4 +++ Plugin.java 24 Jun 2003 08:24:57 -0000 1.5 @@ -69,6 +69,7 @@ @author Mark Womack @author Nicko Cadell + @author Paul Smith <[EMAIL PROTECTED]> @since 1.3 */ public interface Plugin extends OptionHandler { @@ -103,7 +104,7 @@ @return boolean true if the plugin is currently active. */ public boolean isActive(); - + /** Call when the plugin should be stopped. */ public void shutdown(); 1.1 jakarta-log4j/src/java/org/apache/log4j/plugins/Pauseable.java Index: Pauseable.java =================================================================== /* * ============================================================================ * The Apache Software License, Version 1.1 * ============================================================================ * * Copyright (C) 1999 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 "log4j" 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.log4j.plugins; /** * Instances of this interface can be paused, and resumed. * * @author Paul Smith <[EMAIL PROTECTED]> * */ public interface Pauseable { public void setPaused(boolean paused); public boolean isPaused(); }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]