Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Licensed to the Apache Software Foundation (ASF) under one or more
   * contributor license agreements.  See the NOTICE file distributed with
   * this work for additional information regarding copyright ownership.
   * The ASF licenses this file to You under the Apache License, Version 2.0
   * (the "License"); you may not use this file except in compliance with
   * the License.  You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
  * 
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 package org.apache.log4j.varia;
 
This is a very simple filter based on level matching.

The filter admits two options LevelToMatch and AcceptOnMatch. If there is an exact match between the value of the LevelToMatch option and the level of the org.apache.log4j.spi.LoggingEvent, then the decide(org.apache.log4j.spi.LoggingEvent) method returns org.apache.log4j.spi.Filter.ACCEPT in case the AcceptOnMatch option value is set to true, if it is false then org.apache.log4j.spi.Filter.DENY is returned. If there is no match, org.apache.log4j.spi.Filter.NEUTRAL is returned.

Author(s):
Ceki Gülcü
Since:
1.2
 
 public class LevelMatchFilter extends Filter {
  
  
Do we return ACCEPT when a match occurs. Default is true.
 
   boolean acceptOnMatch = true;

  
 
 
  
   public
   void setLevelToMatch(String level) {
      = OptionConverter.toLevel(levelnull);
   }
   
   public
     return  == null ? null : .toString();
   }
   
   public
   void setAcceptOnMatch(boolean acceptOnMatch) {
     this. = acceptOnMatch;
   }
   
   public
   boolean getAcceptOnMatch() {
     return ;
   }
  

  
Return the decision of this filter. Returns org.apache.log4j.spi.Filter.NEUTRAL if the LevelToMatch option is not set or if there is not match. Otherwise, if there is a match, then the returned decision is org.apache.log4j.spi.Filter.ACCEPT if the AcceptOnMatch property is set to true. The returned decision is org.apache.log4j.spi.Filter.DENY if the AcceptOnMatch property is set to false.
 
   public
   int decide(LoggingEvent event) {
     if(this. == null) {
       return .;
     }
     
     boolean matchOccured = false;
     if(this..equals(event.getLevel())) {
       matchOccured = true;
     } 
 
     if(matchOccured) {  
       if(this.)
 	  return .;
       else
 	  return .;
    } else {
      return .;
    }
  }
New to GrepCode? Check out our FAQ X