Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to use Log4j2 AsyncAppender with log4j2.properties

I have defined log4j2.properties as

    ...
    appender.async.type = Async
    appender.async.name = async
    appender.async.appenderRefs.type = AppenderRefs
    appender.async.appenderRefs.consoleAppender.type = AppenderRef
    appender.async.appenderRefs.consoleAppender.ref = console

    rootLogger.level = debug
    rootLogger.appenderRef.console.ref = async
    rootLogger.appenderRef.rolling.ref = rolling

Exception during runtime:

2019-06-28 12:03:27,996 main ERROR Could not create plugin of type class org.apache.logging.log4j.core.appender.AsyncAppender for element Async: java.lang.NullPointerException java.lang.NullPointerException
        at org.apache.logging.log4j.core.config.plugins.visitors.PluginElementVisitor.visit(PluginElementVisitor.java:52)
        at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.injectFields(PluginBuilder.java:180)
        at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:121)
        at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:964)

...

2019-06-28 12:03:27,997 main ERROR Unable to invoke factory method in class org.apache.logging.log4j.core.appender.AsyncAppender for element Async: java.lang.IllegalStateException: No factory method found for class org.apache.logging.log4j.core.appender.AsyncAppender java.lang.IllegalStateException: No factory method found for class org.apache.logging.log4j.core.appender.AsyncAppender
        at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.findFactoryMethod(PluginBuilder.java:234)
        at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:134)
        at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:964)
        at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:904)
        at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:896)
        at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:514)

What is that I'm missing?

like image 440
Abhishek Agarwal Avatar asked Jun 28 '19 07:06

Abhishek Agarwal


People also ask

Can Log4j2 use Log4j properties file?

Log4j 2 doesn't support the Log4j v1 ". properties" format anymore (yet, since v2. 4, Log4j supports a Property format, but its syntax is totally different from v1 format). New formats are XML, JSON, and YAML, see the documentation (note: if you used one of these formats in a file called ".

Where do Log4j2 properties go?

We should put log4j2. properties anywhere in the application's classpath. Log4j2 will scan all classpath locations to find out this file and then load it. We have put the file in resources folder.

How do I use console Appenders in Log4j2?

Log4j2 ConsoleAppender ConfigurationThe target poperty specifies the target of the logging messages i.e. SYSTEM_OUT or SYSTEM_ERR . The follow attribute tells whether the appender should honor the reassignments of System. out or System. err made after the logging configuration has been initialized.


1 Answers

Try below configuration -

appender.async.type = Async
appender.async.name = asyncAppender
appender.async.appenderRef.type = AppenderRef
appender.async.appenderRef.ref = consoleAppender
like image 199
Vikas Sachdeva Avatar answered Oct 15 '22 02:10

Vikas Sachdeva