-
I'm thinking of the following <?xml version="1.0" encoding="UTF-8"?>
<Configuration status="warn">
<Appenders>
<CustomAppender name="customAppender">
<IgnoredExceptions>
<IgnoredException>org.apache.http.NoHttpResponseException</IgnoredException>
</IgnoredExceptions>
</CustomAppender>
</Appenders>
<Loggers>
<Root level="ALL">
<AppenderRef ref="customAppender"/>
</Root>
</Loggers>
</Configuration> And wish I could get @Plugin(name = "CustomAppender", category = Core.CATEGORY_NAME, elementType = Appender.ELEMENT_TYPE)
public class CustomAppender extends AbstractAppender {
private final Set<Class<? extends Throwable>> ignoredExceptions;
protected CustomAppender(String name, Set<Class<? extends Throwable>> ignoredExceptions) {
super(name, null, PatternLayout.createDefaultLayout(), true, Property.EMPTY_ARRAY);
this.ignoredExceptions = ignoredExceptions;
}
@PluginFactory
public static CustomAppender createAppender(
@PluginAttribute("name") String name,
@PluginElement("IgnoredExceptions") Set<Class<? extends Throwable>> ignoredExceptions) {
return new CustomAppender(name, ignoredExceptions);
}
@Override
public void append(LogEvent event) {
var thrown = event.getThrown();
if (thrown != null && ignoredExceptions.contains(thrown.getClass())) {
//noop
return;
}
//do stuff
}
} But this config will fail at runtime. I tried different combinations of Could someone please assist me with plugin setup? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 5 replies
-
@yvasyliev, could you try |
Beta Was this translation helpful? Give feedback.
-
You can create a wrapper class something like this: @Plugin(name = "ExceptionType", category = "Core", elementType = "ExceptionType")
public class ExceptionType {
private final Class<? extends Throwable> type;
private ExceptionType(Class<? extends Throwable> type) { this.type = type; }
public Class<? extends Throwable> getType() { return type; }
@PluginFactory
public static ExceptionType create(@PluginValue("type") String className) {
Class<? extends Throwable> type = Class.forName(className).asSubclass(Throwable.class);
return new ExceptionType(type);
}
} Then, you can use a <Appenders>
<CustomAppender>
<ExceptionType>com.example.FooException</ExceptionType>
<ExceptionType>com.example.BarException</ExceptionType>
<!-- ... -->
</CustomAppender>
</Appenders> |
Beta Was this translation helpful? Give feedback.
-
After some tries, I found solution that solves my task.
The classes above will properly read a config like: <?xml version="1.0" encoding="UTF-8"?>
<Configuration status="warn">
<Appenders>
<CustomAppender name="customAppender">
<IgnoredExceptions>
<IgnoredException>org.apache.http.NoHttpResponseException</IgnoredException>
</IgnoredExceptions>
</CustomAppender>
</Appenders>
<Loggers>
<Root level="ALL">
<AppenderRef ref="customAppender"/>
</Root>
</Loggers>
</Configuration> But during the research I found a fantastic behavior:
Also, |
Beta Was this translation helpful? Give feedback.
After some tries, I found solution that solves my task.
IgnoredException.java