简体   繁体   中英

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?

Try below configuration -

appender.async.type = Async
appender.async.name = asyncAppender
appender.async.appenderRef.type = AppenderRef
appender.async.appenderRef.ref = consoleAppender

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM