1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache license, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the license for the specific language governing permissions and 15 * limitations under the license. 16 */ 17 18 package org.apache.logging.log4j.core; 19 20 import org.apache.logging.log4j.Level; 21 import org.apache.logging.log4j.Marker; 22 import org.apache.logging.log4j.message.Message; 23 import org.apache.logging.log4j.util.EnglishEnums; 24 25 /** 26 * Interface that must be implemented to allow custom event filtering. It is highly recommended that 27 * applications make use of the Filters provided with this implementation before creating their own. 28 * 29 * This interface supports "global" filters (i.e. - all events must pass through them first), attached to 30 * specific loggers and associated with Appenders. It is recommended that, where possible, Filter implementations 31 * create a generic filtering method that can be called from any of the filter methods. 32 */ 33 public interface Filter { 34 35 /** 36 * The result that can returned from a filter method call. 37 */ 38 public enum Result { 39 /** 40 * The event will be processed without further filtering based on the log Level. 41 */ 42 ACCEPT, 43 /** 44 * No decision could be made, further filtering should occur. 45 */ 46 NEUTRAL, 47 /** 48 * The event should not be processed. 49 */ 50 DENY; 51 52 /** 53 * Returns the Result for the given string. 54 * 55 * @param name The Result enum name, case-insensitive. If null, returns, null 56 * @return a Result enum value or null if name is null 57 */ 58 public static Result toResult(final String name) { 59 return toResult(name, null); 60 } 61 62 /** 63 * Returns the Result for the given string. 64 * 65 * @param name The Result enum name, case-insensitive. If null, returns, defaultResult 66 * @param defaultResult the Result to return if name is null 67 * @return a Result enum value or null if name is null 68 */ 69 public static Result toResult(final String name, final Result defaultResult) { 70 return EnglishEnums.valueOf(Result.class, name, defaultResult); 71 } 72 } 73 74 /** 75 * Returns the result that should be returned when the filter does not match the event. 76 * @return the Result that should be returned when the filter does not match the event. 77 */ 78 Result getOnMismatch(); 79 /** 80 * Returns the result that should be returned when the filter matches the event. 81 * @return the Result that should be returned when the filter matches the event. 82 */ 83 Result getOnMatch(); 84 85 /** 86 * Filter an event. 87 * @param logger The Logger. 88 * @param level The event logging Level. 89 * @param marker The Marker for the event or null. 90 * @param msg String text to filter on. 91 * @param params An array of parameters or null. 92 * @return the Result. 93 */ 94 Result filter(Logger logger, Level level, Marker marker, String msg, Object... params); 95 96 /** 97 * Filter an event. 98 * @param logger The Logger. 99 * @param level The event logging Level. 100 * @param marker The Marker for the event or null. 101 * @param msg Any Object. 102 * @param t A Throwable or null. 103 * @return the Result. 104 */ 105 Result filter(Logger logger, Level level, Marker marker, Object msg, Throwable t); 106 107 /** 108 * Filter an event. 109 * @param logger The Logger. 110 * @param level The event logging Level. 111 * @param marker The Marker for the event or null. 112 * @param msg The Message 113 * @param t A Throwable or null. 114 * @return the Result. 115 */ 116 Result filter(Logger logger, Level level, Marker marker, Message msg, Throwable t); 117 118 /** 119 * Filter an event. 120 * @param event The Event to filter on. 121 * @return the Result. 122 */ 123 Result filter(LogEvent event); 124 125 }