mwomack 2003/03/19 23:18:32 Modified: src/java/org/apache/log4j/filter SetLocationInfoFilter.java NDCMatchFilter.java MessageMatchFilter.java MDCMatchFilter.java MatchFilterBase.java LevelRangeMatchFilter.java LevelMatchFilter.java Added: src/java/org/apache/log4j/filter LoggerNameMatchFilter.java Log: Jalopy-ized & checkstyled versions. Revision Changes Path 1.2 +81 -35 jakarta-log4j-sandbox/src/java/org/apache/log4j/filter/SetLocationInfoFilter.java Index: SetLocationInfoFilter.java =================================================================== RCS file: /home/cvs/jakarta-log4j-sandbox/src/java/org/apache/log4j/filter/SetLocationInfoFilter.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- SetLocationInfoFilter.java 4 Feb 2003 06:28:16 -0000 1.1 +++ SetLocationInfoFilter.java 20 Mar 2003 07:18:32 -0000 1.2 @@ -1,68 +1,114 @@ /* - * Copyright (C) The Apache Software Foundation. All rights reserved. + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ * - * 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. */ + * 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.filter; import org.apache.log4j.spi.Filter; import org.apache.log4j.spi.LoggingEvent; + /** SetLocationInfoFilter is pass through filter that simply calls - [EMAIL PROTECTED] LoggingEvent#getLocationInformation} method of every - LoggingEvent that is sent to it. After calling the method, it - returns [EMAIL PROTECTED] Filter#NEUTRAL} to send the event to the next + [EMAIL PROTECTED] LoggingEvent#getLocationInformation} method of every + LoggingEvent that is sent to it. After calling the method, it + returns [EMAIL PROTECTED] Filter#NEUTRAL} to send the event to the next filter. - + <p><bold>Use of this filter is probably not typical.</bold> - Its primary purpose is to increase throughput performance for + Its primary purpose is to increase throughput performance for appenders like SocketAppender and SocketHubAppender that send - logging events to remote clients. These appenders have the option + logging events to remote clients. These appenders have the option to set the location info for every event appended to them so that - the client can see where the event was logged in the code. - However, resolving the location info for every event can be costly - performance-wise, and will reduce the number of events per second - that can be appended. This can affect performance in the - application that is logging the event. Chances are that one does + the client can see where the event was logged in the code. + However, resolving the location info for every event can be costly + performance-wise, and will reduce the number of events per second + that can be appended. This can affect performance in the + application that is logging the event. Chances are that one does not want the location info for every event, but rather for a smaller set of events that are of interest. - + <p>SetLocationInfoFilter can be placed at the end of a filter - chain configured for an appender. After the event has been - filtered through the chain, it will pass through the - SetLocationInfoFilter, thus setting the location info for just - that event (this assumes that the location info setting of the - appender has been set to false). Using subclasses of the - MatchFilterBase class, one can configure the filter chain to - accept all events sent to the appender, while only setting the + chain configured for an appender. After the event has been + filtered through the chain, it will pass through the + SetLocationInfoFilter, thus setting the location info for just + that event (this assumes that the location info setting of the + appender has been set to false). Using subclasses of the + MatchFilterBase class, one can configure the filter chain to + accept all events sent to the appender, while only setting the location info for a select set of events. Please see the examples for information on how to do this. - - <p>Please review the available filters in the + + <p>Please review the available filters in the org.apache.log4j.filters package. Most of these subclass the MatchFilterBase class and are easily configurable for use in - log4j filter chains. - - <p>(Note that any log4j filter can be used in an appender filter + log4j filter chains. + + <p>(Note that any log4j filter can be used in an appender filter chain, but it needs to support the return of the [EMAIL PROTECTED] Filter#NEUTRAL} value from its decide method. - MatchFilterBase subclasses simply expose this functionality + MatchFilterBase subclasses simply expose this functionality directly as part of their configuration.) - + @author Mark Womack - + @since 1.3 */ public class SetLocationInfoFilter extends Filter { - /** - Sets the LocationInfo for the event and returns - [EMAIL PROTECTED] Filter#NEUTRAL} to pass the event to the next filter. */ + Sets the LocationInfo for the event and returns + [EMAIL PROTECTED] Filter#NEUTRAL} to pass the event to the next filter. + + @param event The logging event to filter. + @return int Always returns Filter.NEUTRAL. */ public int decide(LoggingEvent event) { event.getLocationInformation(); + return Filter.NEUTRAL; } -} \ No newline at end of file +} 1.2 +79 -33 jakarta-log4j-sandbox/src/java/org/apache/log4j/filter/NDCMatchFilter.java Index: NDCMatchFilter.java =================================================================== RCS file: /home/cvs/jakarta-log4j-sandbox/src/java/org/apache/log4j/filter/NDCMatchFilter.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- NDCMatchFilter.java 4 Feb 2003 06:28:16 -0000 1.1 +++ NDCMatchFilter.java 20 Mar 2003 07:18:32 -0000 1.2 @@ -1,24 +1,64 @@ /* - * Copyright (C) The Apache Software Foundation. All rights reserved. + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ * - * 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. */ + * 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.filter; -import org.apache.log4j.NDC; -import org.apache.log4j.spi.Filter; import org.apache.log4j.spi.LoggingEvent; -import org.apache.log4j.helpers.OptionConverter; + /** The NDCMatchFilter matches a configured value against the NDC value of a logging event. - + <p>The filter admits two options <b>ValueToMatch</b> and <b>ExactMatch</b>. - + <p>As the name indicates, the value of <b>ValueToMatch</b> property determines the string value to match. If <b>ExactMatch</b> is set to true, a match will occur only when <b>ValueToMatch</b> exactly @@ -27,36 +67,39 @@ will occur when <b>ValueToMatch</b> is contained anywhere within the NDC value. The <b>ExactMatch</b> property is set to <code>false</code> by default. - + <p>Note that by default <b>ValueToMatch</b> is set to <code>null</code> and will only match an empty NDC stack. <p>For more information about how the logging event will be - passed to the appender for reporting, please see + passed to the appender for reporting, please see the [EMAIL PROTECTED] MatchFilterBase} class. @author Mark Womack - + @since 1.3 */ public class NDCMatchFilter extends MatchFilterBase { - /** The value to match in the NDC value of the LoggingEvent. */ String valueToMatch; - + /** Do we look for an exact match or just a "contains" match? */ boolean exactMatch = false; /** - Sets the value to match in the NDC value of the LoggingEvent. */ + Sets the value to match in the NDC value of the LoggingEvent. + + @param value The value to match. */ public void setValueToMatch(String value) { valueToMatch = value; } - + /** - Gets the value to match in the NDC value of the LoggingEvent. */ + Gets the value to match in the NDC value of the LoggingEvent. + + @return String The value to match. */ public String getValueToMatch() { return valueToMatch; } @@ -65,38 +108,40 @@ Set to true if configured value must exactly match the NDC value of the LoggingEvent. Set to false if the configured value must only be contained in the NDC value of the - LoggingEvent. Default is false. */ + LoggingEvent. Default is false. + + @param exact True if an exact match should be checked for. */ public void setExactMatch(boolean exact) { exactMatch = exact; } - + + /** + Returns the true if an exact match will be checked for. + + @return boolean True if an exact match will be checked for. */ public boolean getExactMatch() { return exactMatch; } - + /** If <b>ExactMatch</b> is set to true, returns true only when - <b>ValueToMatch</b> exactly matches the NDC value of the + <b>ValueToMatch</b> exactly matches the NDC value of the logging event. If the <b>ExactMatch</b> property - is set to <code>false</code>, returns true when + is set to <code>false</code>, returns true when <b>ValueToMatch</b> is contained anywhere within the NDC - value. Otherwise, false is returned. */ - protected boolean match(LoggingEvent event) { + value. Otherwise, false is returned. + @param event The logging event to match against. + @return boolean True if matches criteria. */ + protected boolean match(LoggingEvent event) { // get the ndc value for the event String eventNDC = event.getNDC(); - + // check for a match - // if the NDC stack is empty if (eventNDC == null) { // return true if are we matching a null - if (valueToMatch == null) { - return true; - // else return false - } else { - return false; - } + return (valueToMatch == null); } else { // try to match the configured non-null value if (valueToMatch != null) { @@ -105,7 +150,8 @@ } else { return (eventNDC.indexOf(valueToMatch) != -1); } - // else the value to match is null, so return false + + // else the value to match is null, so return false } else { return false; } 1.2 +80 -24 jakarta-log4j-sandbox/src/java/org/apache/log4j/filter/MessageMatchFilter.java Index: MessageMatchFilter.java =================================================================== RCS file: /home/cvs/jakarta-log4j-sandbox/src/java/org/apache/log4j/filter/MessageMatchFilter.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- MessageMatchFilter.java 4 Feb 2003 06:28:16 -0000 1.1 +++ MessageMatchFilter.java 20 Mar 2003 07:18:32 -0000 1.2 @@ -1,23 +1,64 @@ /* - * Copyright (C) The Apache Software Foundation. All rights reserved. + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ * - * 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. */ + * 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.filter; -import org.apache.log4j.Level; import org.apache.log4j.spi.LoggingEvent; -import org.apache.log4j.helpers.OptionConverter; + /** - MessageMatchFilter is a very simple filter that matches a + MessageMatchFilter is a very simple filter that matches a configured value against the message value of a logging event. - + <p>The filter admits two options <b>MessageToMatch</b> and <b>ExactMatch</b>. - + <p>As the name indicates, the value of <b>MessageToMatch</b> property determines the string value to match. If <b>ExactMatch</b> is set to true, a match will occur only when <b>MessageToMatch</b> exactly @@ -26,12 +67,12 @@ will occur when <b>MessageToMatch</b> is contained anywhere within the message value. The <b>ExactMatch</b> property is set to <code>false</code> by default. - + <p>Note that by default <b>MessageToMatch</b> is set to <code>null</code> and will only match a null message. <p>For more information about how the logging event will be - passed to the appender for reporting, please see + passed to the appender for reporting, please see the [EMAIL PROTECTED] MatchFilterBase} class. @author Mark Womack; @@ -39,7 +80,6 @@ @since 1.3 */ public class MessageMatchFilter extends MatchFilterBase { - /** The message match against. */ String messageToMatch; @@ -49,11 +89,17 @@ boolean exactMatch = false; /** - Sets the string to match against the logging event message. */ - public void setMessageToMatch(String _message) { - messageToMatch = _message; + Sets the string to match against the logging event message. + + @param message The string to match in the message. */ + public void setMessageToMatch(String message) { + messageToMatch = message; } - + + /** + Returns the string to match. + + @return String The string to match in the message. */ public String getMessageToMatch() { return messageToMatch; } @@ -62,24 +108,34 @@ Set to true if configured value must exactly match the message value of the LoggingEvent. Set to false if the configured value must only be contained in the message value of the - LoggingEvent. Default is false. */ + LoggingEvent. Default is false. + + @param exact True if an exact match should be checked for. */ public void setExactMatch(boolean exact) { exactMatch = exact; } - + + /** + Returns the true if an exact match will be checked for. + + @return boolean True if an exact match will be checked for. */ public boolean getExactMatch() { return exactMatch; } - + /** If <b>ExactMatch</b> is set to true, returns true only when - <b>MessageToMatch</b> exactly matches the message value of the + <b>MessageToMatch</b> exactly matches the message value of the logging event. If the <b>ExactMatch</b> property - is set to <code>false</code>, returns true when + is set to <code>false</code>, returns true when <b>MessageToMatch</b> is contained anywhere within the message - value. Otherwise, false is returned. */ + value. Otherwise, false is returned. + + @param event The logging event to match against. + @return boolean True if matches criteria. */ protected boolean match(LoggingEvent event) { String msg = event.getRenderedMessage(); + if (msg == null) { return (messageToMatch == null); } else { @@ -91,7 +147,7 @@ } } } - + return false; } -} \ No newline at end of file +} 1.2 +93 -36 jakarta-log4j-sandbox/src/java/org/apache/log4j/filter/MDCMatchFilter.java Index: MDCMatchFilter.java =================================================================== RCS file: /home/cvs/jakarta-log4j-sandbox/src/java/org/apache/log4j/filter/MDCMatchFilter.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- MDCMatchFilter.java 4 Feb 2003 06:28:16 -0000 1.1 +++ MDCMatchFilter.java 20 Mar 2003 07:18:32 -0000 1.2 @@ -1,30 +1,71 @@ /* - * Copyright (C) The Apache Software Foundation. All rights reserved. + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ * - * 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. */ + * 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.filter; -import org.apache.log4j.MDC; -import org.apache.log4j.spi.Filter; import org.apache.log4j.spi.LoggingEvent; + /** The MDCMatchFilter matches a configured value against the value of a configured key in the MDC of a logging event. - <p>The filter admits three options <b>KeyToMatch</b>, + <p>The filter admits three options <b>KeyToMatch</b>, <b>ValueToMatch</b>, and <b>ExactMatch</b>. - + <p>The value of <b>KeyToMatch</b> property determines which key is used to match against in the MDC. The value of that key is used to test against the <b>ValueToMatch</b property. The <b>KeyToMatch</b> property must be set before this filter can function properly. - - <p>The value of <b>ValueToMatch</b> property determines the + + <p>The value of <b>ValueToMatch</b> property determines the string value to match against. If <b>ExactMatch</b> is set to true, a match will occur only when <b>ValueToMatch</b> exactly matches the MDC value of the logging event. Otherwise, if the @@ -32,53 +73,60 @@ will occur if <b>ValueToMatch</b> is contained anywhere within the MDC value. The <b>ExactMatch</b> property is set to <code>false</code> by default. - + <p>Note that by default the value to match is set to <code>null</code> and will only match if the key is not contained or the value is null in the MDC. <p>For more information about how the logging event will be - passed to the appender for reporting, please see + passed to the appender for reporting, please see the [EMAIL PROTECTED] MatchFilterBase} class. @author Mark Womack - + @since 1.3 */ public class MDCMatchFilter extends MatchFilterBase { - /** The key to match in the MDC of the LoggingEvent. */ String keyToMatch; - + /** The value to match in the MDC value of the LoggingEvent. */ String valueToMatch; - + /** Do we look for an exact match or just a "contains" match? */ boolean exactMatch = false; /** - Sets the key to match in the MDC of the LoggingEvent. */ + Sets the key to match in the MDC of the LoggingEvent. + + @param key The key that will be matched. */ public void setKeyToMatch(String key) { keyToMatch = key; } - + /** - Gets the key to match in the MDC of the LoggingEvent. */ + Gets the key to match in the MDC of the LoggingEvent. + + @return String The key that will be matched. */ public String getKeyToMatch() { return keyToMatch; } /** - Sets the value to match in the NDC value of the LoggingEvent. */ + Sets the value to match in the NDC value of the LoggingEvent. + + @param value The value to match. */ public void setValueToMatch(String value) { valueToMatch = value; } - + /** - Gets the value to match in the NDC value of the LoggingEvent. */ + Gets the value to match in the NDC value of the LoggingEvent. + + @return String The value to match. */ public String getValueToMatch() { return valueToMatch; } @@ -87,45 +135,54 @@ Set to true if configured value must exactly match the MDC value of the LoggingEvent. Set to false if the configured value must only be contained in the MDC value of the - LoggingEvent. Default is false. */ + LoggingEvent. Default is false. + + @param exact True if an exact match should be checked for. */ public void setExactMatch(boolean exact) { exactMatch = exact; } - + + /** + Returns the true if an exact match will be checked for. + + @return boolean True if an exact match will be checked for. */ public boolean getExactMatch() { return exactMatch; } - + + /** + Returns true if a key to match has been configured. + + @return boolean True if a match can be performed. */ protected boolean canMatch() { return (keyToMatch != null); } - + /** If <b>ExactMatch</b> is set to true, returns true only when - <b>ValueToMatch</b> exactly matches the MDC value of the + <b>ValueToMatch</b> exactly matches the MDC value of the logging event. If the <b>ExactMatch</b> property - is set to <code>false</code>, returns true when + is set to <code>false</code>, returns true when <b>ValueToMatch</b> is contained anywhere within the MDC - value. Otherwise, false is returned. */ + value. Otherwise, false is returned. + + @param event The logging event to match against. + @return boolean True if matches criteria. */ protected boolean match(LoggingEvent event) { - // get the mdc value for the key from the event // use the toString() value of the value object Object mdcObject = event.getMDC(keyToMatch); String mdcValue; + if (mdcObject != null) { mdcValue = mdcObject.toString(); } else { mdcValue = null; } - + // check for a match if (mdcValue == null) { - if (valueToMatch == null) { - return true; - } else { - return false; - } + return (valueToMatch == null); } else { if (valueToMatch != null) { if (exactMatch) { 1.2 +124 -60 jakarta-log4j-sandbox/src/java/org/apache/log4j/filter/MatchFilterBase.java Index: MatchFilterBase.java =================================================================== RCS file: /home/cvs/jakarta-log4j-sandbox/src/java/org/apache/log4j/filter/MatchFilterBase.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- MatchFilterBase.java 4 Feb 2003 06:28:16 -0000 1.1 +++ MatchFilterBase.java 20 Mar 2003 07:18:32 -0000 1.2 @@ -1,46 +1,89 @@ /* - * Copyright (C) The Apache Software Foundation. All rights reserved. + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ * - * 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. */ + * 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.filter; +import org.apache.log4j.helpers.LogLog; import org.apache.log4j.spi.Filter; import org.apache.log4j.spi.LoggingEvent; -import org.apache.log4j.helpers.LogLog; + /** This is the abstract base class for many useful filters implemented - in the log4j.filter package. It extends the base [EMAIL PROTECTED] Filter} - class to allow a different return value for a match or a nomatch. + in the log4j.filter package. It extends the base [EMAIL PROTECTED] Filter} + class to allow a different return value for a match or a nomatch. What is specifically tested for matching is implemented in specific subclasses. - + <p>Properties matchReturnValue and noMatchReturnValue can be set programmitcally or from a configuration file. They set the value that will be returned when there is match or when there is not a match, respectively. By default matchReturnValue is set to Filter.ACCEPT and noMatchReturnValue is set to Filter.DENY. - + <p>In addition to being able to set the match and nomatch return values directly, one can instead use the chainPolicy property. Log4j allows for filters to be chained together, each filter deciding whether the logging event should be accepted, denied, or passed on to the next filter. However, for the event to passed - to the next filter, one of the return values must be set to + to the next filter, one of the return values must be set to Filter.NEUTRAL. One can use chainPolicy to accomplish this, passing - it one of the four valid policies: ACCEPT_ON_MATCH (match = - Filter.ACCEPT/nomatch = Filter.NEUTRAL), DENY_ON_MATCH (match = + it one of the four valid policies: ACCEPT_ON_MATCH (match = + Filter.ACCEPT/nomatch = Filter.NEUTRAL), DENY_ON_MATCH (match = Filter.DENY/nomatch = Filter.NEUTRAL), ACCEPT_ON_NOMATCH - (match = Filter.NEUTRAL/nomatch = Filter.ACCEPT), and + (match = Filter.NEUTRAL/nomatch = Filter.ACCEPT), and DENY_ON_NOMATCH (match = Filter.NEUTRAL/nomatch = Filter.DENY). Which policy is used can be set programmatically or from a configuration file. If more than one filter will be attached to a single appender, all but the last one should probably be configured via the chainPolicy property. - + <p>Subclasses are required to implement the match() method. The implementation should test for a match, returning true if there is a match and false if there is nomatch. Subclasses can also @@ -48,44 +91,45 @@ only do so if they will be unable to perform the match code due to misconfiguration. By default, canMatch() will always return true. - + <p>Developers are encouraged to extend this base class when implementing their own filters. For examples of how - to use and extend this base class, please see the various + to use and extend this base class, please see the various filters implemented in the log4j.filters package. - + @author Mark Womack - + @since 1.3 */ public abstract class MatchFilterBase extends Filter { - /** Chain policy constant = AcceptOnMatch. */ - public static final String ACCEPT_ON_MATCH = "AcceptOnMatch"; + public static final String ACCEPT_ON_MATCH = "AcceptOnMatch"; /** Chain policy constant = DenyOnMatch. */ - public static final String DENY_ON_MATCH = "DenyOnMatch"; + public static final String DENY_ON_MATCH = "DenyOnMatch"; /** Chain policy constant = AcceptOnNomatch. */ - public static final String ACCEPT_ON_NOMATCH = "AcceptOnNomatch"; + public static final String ACCEPT_ON_NOMATCH = "AcceptOnNomatch"; /** Chain policy constant = DenyOnNomatch. */ - public static final String DENY_ON_NOMATCH = "DenyOnNomatch"; + public static final String DENY_ON_NOMATCH = "DenyOnNomatch"; /** Chain policy constant = UnknownPolicy. */ - public static final String UNKNOWN_POLICY = "UnknownPolicy"; - + public static final String UNKNOWN_POLICY = "UnknownPolicy"; + /** The value that will be returned upon a successful match. */ protected int matchReturnValue = ACCEPT; - - /** + + /** The value that will be returned upon an unsuccessful match */ protected int noMatchReturnValue = DENY; - + /** Set the value to return upon a successful match. Valid - string values are "ACCEPT", "DENY", and "NEUTRAL". */ + string values are "ACCEPT", "DENY", and "NEUTRAL". + + @param filterReturnValue The return value if there is a match. */ public void setMatchReturnValue(String filterReturnValue) { if (filterReturnValue.equalsIgnoreCase("accept")) { matchReturnValue = ACCEPT; @@ -97,24 +141,29 @@ LogLog.error("invalid matchReturnValue: " + filterReturnValue); } } - + /** Gets the value that will be returned upon a successful - match. */ + match. + + @return String The return value if there is a match. */ public String getMatchReturnValue() { - if (matchReturnValue == ACCEPT) + if (matchReturnValue == ACCEPT) { return "accept"; - else if (matchReturnValue == DENY) + } else if (matchReturnValue == DENY) { return "deny"; - else if (matchReturnValue == NEUTRAL) + } else if (matchReturnValue == NEUTRAL) { return "neutral"; - else + } else { return "unknown"; // this one should never happen + } } /** Set the value to return upon a successful match. Valid - string values are "ACCEPT", "DENY", and "NEUTRAL". */ + string values are "ACCEPT", "DENY", and "NEUTRAL". + + @param filterReturnValue The return value if there is no match. */ public void setNoMatchReturnValue(String filterReturnValue) { if (filterReturnValue.equalsIgnoreCase("accept")) { noMatchReturnValue = ACCEPT; @@ -126,26 +175,31 @@ LogLog.error("invalid noMatchReturnValue: " + filterReturnValue); } } - + /** Gets the value that will be returned upon an unsuccessful - match. */ + match. + + @return String The return value if there is no match. */ public String getNoMatchReturnValue() { - if (noMatchReturnValue == ACCEPT) + if (noMatchReturnValue == ACCEPT) { return "accept"; - else if (noMatchReturnValue == DENY) + } else if (noMatchReturnValue == DENY) { return "deny"; - else if (noMatchReturnValue == NEUTRAL) + } else if (noMatchReturnValue == NEUTRAL) { return "neutral"; - else + } else { return "unknown"; // this one should never happen + } } - + /** Sets the match and nomatch return values based on a "policy" string. Valid values for the policy string are defined as - constants for this class: ACCEPT_ON_MATCH, DENY_ON_MATCH, - ACCEPT_ON_NOMATCH, DENY_ON_NOMATCH. */ + constants for this class: ACCEPT_ON_MATCH, DENY_ON_MATCH, + ACCEPT_ON_NOMATCH, DENY_ON_NOMATCH. + + @param policyStr The policy to use. */ public void setChainPolicy(String policyStr) { if (policyStr.equalsIgnoreCase(ACCEPT_ON_MATCH)) { matchReturnValue = ACCEPT; @@ -170,29 +224,34 @@ current values do not match a known policy setting, then the value of UNKNOWN_PLOCY is returned. Valid return values for the policy string are defined as - constants for this class: ACCEPT_ON_MATCH, DENY_ON_MATCH, - ACCEPT_ON_NOMATCH, DENY_ON_NOMATCH, and UNKNOWN_POLICY. */ + constants for this class: ACCEPT_ON_MATCH, DENY_ON_MATCH, + ACCEPT_ON_NOMATCH, DENY_ON_NOMATCH, and UNKNOWN_POLICY. + + @return String The policy to use. */ public String getChainPolicy() { - if (matchReturnValue == ACCEPT && noMatchReturnValue == NEUTRAL) { + if ((matchReturnValue == ACCEPT) && (noMatchReturnValue == NEUTRAL)) { return ACCEPT_ON_MATCH; - } else if (matchReturnValue == DENY && noMatchReturnValue == NEUTRAL) { + } else if ((matchReturnValue == DENY) && (noMatchReturnValue == NEUTRAL)) { return DENY_ON_MATCH; - } else if (matchReturnValue == NEUTRAL && noMatchReturnValue == ACCEPT) { + } else if ((matchReturnValue == NEUTRAL) && (noMatchReturnValue == ACCEPT)) { return ACCEPT_ON_NOMATCH; - } else if (matchReturnValue == NEUTRAL && noMatchReturnValue == DENY) { + } else if ((matchReturnValue == NEUTRAL) && (noMatchReturnValue == DENY)) { return DENY_ON_NOMATCH; } else { return UNKNOWN_POLICY; } } - + /** Implementation that calls the canMatch() and match() methods of subclasses. If a match test can be performed (canMatch() returned true), then either the configured matchReturnValue or noMatchReturnValue will be returned. If no match test can be performed (canMatch() returned false), then Filter.NEUTRAL - is returned. */ + is returned. + + @param event The event to filter. + @return int A Filter value to indicate what do with event. */ public int decide(LoggingEvent event) { if (canMatch()) { if (match(event)) { @@ -200,9 +259,9 @@ } else { return noMatchReturnValue; } - } - else + } else { return NEUTRAL; + } } /** @@ -210,14 +269,19 @@ it is possible that no match test can/should be performed due to a misconfiguration. This method should return true if a match test can be performed, and false if it cannot be performed. The - default version always returns true. */ + default version always returns true. + + @return boolean True if a match can be performed. */ protected boolean canMatch() { return true; } - + /** Subclasses must implement this method to perform the specific match test that they require. This method should return true - if a match is made, and false if no match is made. */ - abstract protected boolean match(LoggingEvent event); -} \ No newline at end of file + if a match is made, and false if no match is made. + + @param event The event to match against. + @return boolean True if a match occurred. */ + protected abstract boolean match(LoggingEvent event); +} 1.2 +79 -26 jakarta-log4j-sandbox/src/java/org/apache/log4j/filter/LevelRangeMatchFilter.java Index: LevelRangeMatchFilter.java =================================================================== RCS file: /home/cvs/jakarta-log4j-sandbox/src/java/org/apache/log4j/filter/LevelRangeMatchFilter.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- LevelRangeMatchFilter.java 4 Feb 2003 06:28:16 -0000 1.1 +++ LevelRangeMatchFilter.java 20 Mar 2003 07:18:32 -0000 1.2 @@ -1,27 +1,70 @@ /* - * Copyright (C) The Apache Software Foundation. All rights reserved. + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ * - * 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. */ + * 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.filter; import org.apache.log4j.Level; import org.apache.log4j.spi.LoggingEvent; + /** - LevelMatchFilter is a very simple filter based on level matching, - which can be used to reject logging events with levels outside a - certain range. If they levels are within the range, then the + LevelMatchFilter is a very simple filter based on level matching, + which can be used to reject logging events with levels outside a + certain range. If they levels are within the range, then the match() method returns true, else it returns false. - + <p>If <code>LevelMin</code> is not defined, then there is no minimum acceptable level (ie a level is never rejected for being too "low"/unimportant). If <code>LevelMax</code> is not defined, then there is no maximum acceptable level (ie a level is never rejected for being too "high"/important). - + <p>Refer to the [EMAIL PROTECTED] org.apache.log4j.AppenderSkeleton#setThreshold setThreshold} method available to <code>all</code> appenders extending [EMAIL PROTECTED] @@ -29,62 +72,72 @@ filter out events by level. <p>For more information about how the logging event will be - passed to the appender for reporting, please see + passed to the appender for reporting, please see the [EMAIL PROTECTED] MatchFilterBase} class. - + @author Simon Kitching - @author based on code by Ceki Gülcü + @author based on code by Ceki Gülcü @author Mark Womack; @since 1.3 */ public class LevelRangeMatchFilter extends MatchFilterBase { - /** Minimum level to match against. */ - Level levelMin; - + private Level levelMin; + /** Maximum level to match against. */ - Level levelMax; + private Level levelMax; /** - Set the <code>LevelMax</code> option. */ + Set the <code>LevelMax</code> option. + + @param levelMax The maximum level to match. */ public void setLevelMax(Level levelMax) { this.levelMax = levelMax; } /** - Get the value of the <code>LevelMax</code> option. */ + Get the value of the <code>LevelMax</code> option. + + @return the maximum level that will be matched. */ public Level getLevelMax() { return levelMax; } /** - Set the <code>LevelMin</code> option. */ + Set the <code>LevelMin</code> option. + + @param levelMin The minumum level to match. */ public void setLevelMin(Level levelMin) { this.levelMin = levelMin; } /** - Get the value of the <code>LevelMin</code> option. */ + Get the value of the <code>LevelMin</code> option. + + @return The minimum level that will be matched. */ public Level getLevelMin() { return levelMin; } - + /** Returns true if the the level of the logging event is in the configured range of <code>LevelMin</code> and - <code>LevelMax</code>. */ + <code>LevelMax</code>. + + @param event The logging event to match against. + @return true if there is a match. */ protected boolean match(LoggingEvent event) { - if(this.levelMin != null) { - if (event.getLevel().isGreaterOrEqual(levelMin) == false) { + if (this.levelMin != null) { + if (!event.getLevel().isGreaterOrEqual(levelMin)) { // level of event is less than minimum return false; } } - if(this.levelMax != null) { + if (this.levelMax != null) { if (event.getLevel().toInt() > levelMax.toInt()) { // level of event is greater than maximum // Alas, there is no Level.isGreater method. and using @@ -97,4 +150,4 @@ // return true match return true; } -} \ No newline at end of file +} 1.2 +70 -18 jakarta-log4j-sandbox/src/java/org/apache/log4j/filter/LevelMatchFilter.java Index: LevelMatchFilter.java =================================================================== RCS file: /home/cvs/jakarta-log4j-sandbox/src/java/org/apache/log4j/filter/LevelMatchFilter.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- LevelMatchFilter.java 4 Feb 2003 06:28:16 -0000 1.1 +++ LevelMatchFilter.java 20 Mar 2003 07:18:32 -0000 1.2 @@ -1,62 +1,114 @@ /* - * Copyright (C) The Apache Software Foundation. All rights reserved. + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ * - * 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. */ + * 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.filter; import org.apache.log4j.Level; -import org.apache.log4j.spi.LoggingEvent; import org.apache.log4j.helpers.OptionConverter; +import org.apache.log4j.spi.LoggingEvent; + /** LevelMatchFilter is a very simple filter that matches a configured log level against the log level of a logging event. If they levels are the same, then the match() method returns true, else it returns false. - + <p>If a LevelMatchFilter is not configured with a level to match, then the canMatch() method will return false. - + <p>For more information about how the logging event will be - passed to the appender for reporting, please see + passed to the appender for reporting, please see the [EMAIL PROTECTED] MatchFilterBase} class. - + @author Ceki Gülcü @author Mark Womack; @since 1.3 */ public class LevelMatchFilter extends MatchFilterBase { - /** The level to match against. */ - Level levelToMatch; + private Level levelToMatch; /** - Sets the level to match against. */ + Sets the level to match against. + + @param level The level to match against. */ public void setLevelToMatch(String level) { levelToMatch = OptionConverter.toLevel(level, null); } - + /** - Gets the level that will be matched against. */ + Gets the level that will be matched against. + + @return the level that will be matched against. */ public String getLevelToMatch() { - return levelToMatch == null ? null : levelToMatch.toString(); + return (levelToMatch == null) ? null : levelToMatch.toString(); } /** Overrides the implementation from the base class to return - false if the levelToMatch has not been configured. */ + false if the levelToMatch has not been configured. + + @return returns true if a match can be performed. */ protected boolean canMatch() { return (levelToMatch != null); } + /** Returns true if the levelToMatch matches the level of the - logging event. */ + logging event. + + @param event The logging event to match against. + @return true if there is a match. */ protected boolean match(LoggingEvent event) { return (levelToMatch.equals(event.getLevel())); } -} \ No newline at end of file +} 1.1 jakarta-log4j-sandbox/src/java/org/apache/log4j/filter/LoggerNameMatchFilter.java Index: LoggerNameMatchFilter.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.filter; import org.apache.log4j.spi.LoggingEvent; import java.util.Vector; /** LoggerNameMatchFilter is a very simple filter that matches a configured set of values against the name of the logger that sent the logger event. <p>The filter admits two options <b>LoggerNameToMatch</b> and <b>ExactMatch</b>. <p>As the name indicates, the value of <b>LoggerNameToMatch</b> property determines the string value to match. If <b>ExactMatch</b> is set to true, a match will occur only when <b>LoggerNameToMatch</b> exactly matches name of the logger generating the logging event. Otherwise, if the <b>ExactMatch</b> property is set to <code>false</code>, a match will occur when <b>LoggerNameToMatch</b> is contained anywhere within the logger name. The <b>ExactMatch</b> property is set to <code>false</code> by default. <p>Note that more than one logger name can be configured by calling the <b>setLoggerNameToMatch</b> method multiple times. <p>For more information about how the logging event will be passed to the appender for reporting, please see the [EMAIL PROTECTED] MatchFilterBase} class. @author Mark Womack; @since 1.3 */ public class LoggerNameMatchFilter extends MatchFilterBase { /** Vector to store the logger names to match. */ protected Vector nameArray = new Vector(); /** The message match against. */ protected String messageToMatch; /** Do we look for an exact match or just a "contains" match? */ protected boolean exactMatch = false; /** Adds a name to an array used to test the name of the logger that generated the event. @param loggerName logger name to match. */ public void setLoggerName(String loggerName) { nameArray.add(loggerName); } /** Set to true if configured value must exactly match the name of the logger that generated the LoggingEvent. Set to false if the configured value must only be contained in the name value of the LoggingEvent. Default is false. @param exact true if an exact match is required. */ public void setExactMatch(boolean exact) { exactMatch = exact; } /** Returns the value of exact match. @return boolean return the current value of exactMatch property. */ public boolean getExactMatch() { return exactMatch; } /** If <b>ExactMatch</b> is set to true, returns true only when <b>LoggerNameToMatch</b> exactly matches the categoryName value of the logging event. If the <b>ExactMatch</b> property is set to <code>false</code>, returns true when <b>LoggerNameToMatch</b> is contained anywhere within the categoryName value. Otherwise, false is returned. @param event the logging event to match against. @return boolean returns true if matches current configuration. */ protected boolean match(LoggingEvent event) { int size = nameArray.size(); for (int x = 0; x < size; x++) { if (exactMatch) { if (event.categoryName.equals((String) nameArray.elementAt(x))) { return true; } } else { if (event.categoryName.indexOf((String) nameArray.elementAt(x)) != -1) { return true; } } } return false; } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]