How to configure null appender in log4j2

Log4j 1. * has an appender class of zero , but I could not find the equivalent in log4j 2. Is it there? How to configure null appender in log4j2.xml?

+6
source share
3 answers

There is a NullAppender class of Log4j2 version 2.7. There were no versions before. The name that it uses in the configuration file is "Null". It can be added to the Appenders list as follows:

<Appenders> <Null name="arbritrary_name" /> </Appenders> 
+3
source

Use the CountingNoOp app.

 <Appenders> <CountingNoOp name="DEV_NULL" /> </Appenders> 
+2
source

NullAppendar was basically a (almost) empty implementation of the Appender interface, using AppenderSkeleton as the base class. Doing the same in Log4j2 is trivial, but for its operation you will need the template code, see the Apache Documentation in user add-ons.

 @Plugin(name = "NullAppender", category = "Core", elementType = "appender", printObject = true) public class NullAppender extends AbstractAppender { private static final long serialVersionUID = -701612541126635333L; private NullAppender(String name, Filter filter, Layout<? extends Serializable> layout) { super(name, filter, layout); } @Override public void append(LogEvent event) { // do exactly nothing } // blatantly stolen from the Apache doc, all errors (C) by me @PluginFactory public static NullAppender createAppender(@PluginAttribute("name") String name, @PluginElement("Layout") Layout layout, @PluginElement("Filters") Filter filter) { if (name == null) { LOGGER.error("No name provided for NullAppender"); return null; } if (layout == null) { layout = PatternLayout.createDefaultLayout(); } return new NullAppender(name, filter, layout); } } 
+1
source

All Articles