001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache license, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the license for the specific language governing permissions and 015 * limitations under the license. 016 */ 017package org.apache.logging.log4j.core.filter; 018 019import org.apache.logging.log4j.Level; 020import org.apache.logging.log4j.Marker; 021import org.apache.logging.log4j.core.Filter; 022import org.apache.logging.log4j.core.LogEvent; 023import org.apache.logging.log4j.core.Logger; 024import org.apache.logging.log4j.core.config.Node; 025import org.apache.logging.log4j.core.config.plugins.Plugin; 026import org.apache.logging.log4j.core.config.plugins.PluginBuilderFactory; 027import org.apache.logging.log4j.message.Message; 028 029import org.apache.logging.log4j.util.PerformanceSensitive; 030 031/** 032 * This filter returns the onMatch result if there is no marker in the LogEvent. 033 */ 034@Plugin(name = "NoMarkerFilter", category = Node.CATEGORY, elementType = Filter.ELEMENT_TYPE, printObject = true) 035@PerformanceSensitive("allocation") 036public final class NoMarkerFilter extends AbstractFilter { 037 038 private NoMarkerFilter(final Result onMatch, final Result onMismatch) { 039 super(onMatch, onMismatch); 040 } 041 042 @Override 043 public Result filter(final Logger logger, final Level level, final Marker marker, final String msg, 044 final Object... params) { 045 return filter(marker); 046 } 047 048 @Override 049 public Result filter(final Logger logger, final Level level, final Marker marker, final Object msg, 050 final Throwable t) { 051 return filter(marker); 052 } 053 054 @Override 055 public Result filter(final Logger logger, final Level level, final Marker marker, final Message msg, 056 final Throwable t) { 057 return filter(marker); 058 } 059 060 @Override 061 public Result filter(final LogEvent event) { 062 return filter(event.getMarker()); 063 } 064 065 @Override 066 public Result filter(final Logger logger, final Level level, final Marker marker, final String msg, 067 final Object p0) { 068 return filter(marker); 069 } 070 071 @Override 072 public Result filter(final Logger logger, final Level level, final Marker marker, final String msg, 073 final Object p0, final Object p1) { 074 return filter(marker); 075 } 076 077 @Override 078 public Result filter(final Logger logger, final Level level, final Marker marker, final String msg, 079 final Object p0, final Object p1, final Object p2) { 080 return filter(marker); 081 } 082 083 @Override 084 public Result filter(final Logger logger, final Level level, final Marker marker, final String msg, 085 final Object p0, final Object p1, final Object p2, final Object p3) { 086 return filter(marker); 087 } 088 089 @Override 090 public Result filter(final Logger logger, final Level level, final Marker marker, final String msg, 091 final Object p0, final Object p1, final Object p2, final Object p3, 092 final Object p4) { 093 return filter(marker); 094 } 095 096 @Override 097 public Result filter(final Logger logger, final Level level, final Marker marker, final String msg, 098 final Object p0, final Object p1, final Object p2, final Object p3, 099 final Object p4, final Object p5) { 100 return filter(marker); 101 } 102 103 @Override 104 public Result filter(final Logger logger, final Level level, final Marker marker, final String msg, 105 final Object p0, final Object p1, final Object p2, final Object p3, 106 final Object p4, final Object p5, final Object p6) { 107 return filter(marker); 108 } 109 110 @Override 111 public Result filter(final Logger logger, final Level level, final Marker marker, final String msg, 112 final Object p0, final Object p1, final Object p2, final Object p3, 113 final Object p4, final Object p5, final Object p6, 114 final Object p7) { 115 return filter(marker); 116 } 117 118 @Override 119 public Result filter(final Logger logger, final Level level, final Marker marker, final String msg, 120 final Object p0, final Object p1, final Object p2, final Object p3, 121 final Object p4, final Object p5, final Object p6, 122 final Object p7, final Object p8) { 123 return filter(marker); 124 } 125 126 @Override 127 public Result filter(final Logger logger, final Level level, final Marker marker, final String msg, 128 final Object p0, final Object p1, final Object p2, final Object p3, 129 final Object p4, final Object p5, final Object p6, 130 final Object p7, final Object p8, final Object p9) { 131 return filter(marker); 132 } 133 134 private Result filter(final Marker marker) { 135 return null == marker ? onMatch : onMismatch; 136 } 137 138 139 @PluginBuilderFactory 140 public static Builder newBuilder() { 141 return new Builder(); 142 } 143 144 public static class Builder extends AbstractFilterBuilder<Builder> implements org.apache.logging.log4j.core.util.Builder<NoMarkerFilter> { 145 146 @Override 147 public NoMarkerFilter build() { 148 return new NoMarkerFilter(this.getOnMatch(), this.getOnMismatch()); 149 } 150 } 151}