No appenders are available for AsyncAppender Async

No appenders are available for AsyncAppender Async

If you are apache log4j for logging and getting below exception which running the code:

java.lang.ExceptionInInitializerError
	at sun.reflect.GeneratedSerializationConstructorAccessor3.newInstance(Unknown Source)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
	at org.objenesis.instantiator.sun.SunReflectionFactoryInstantiator.newInstance(SunReflectionFactoryInstantiator.java:45)
	at org.objenesis.ObjenesisBase.newInstance(ObjenesisBase.java:73)
	at org.mockito.internal.creation.jmock.ClassImposterizer.createProxy(ClassImposterizer.java:142)
	at org.mockito.internal.creation.jmock.ClassImposterizer.imposterise(ClassImposterizer.java:61)
	at org.mockito.internal.creation.jmock.ClassImposterizer.imposterise(ClassImposterizer.java:52)
	at org.mockito.internal.creation.CglibMockMaker.createMock(CglibMockMaker.java:24)
	at org.mockito.internal.util.MockUtil.createMock(MockUtil.java:32)
	at org.mockito.internal.MockitoCore.mock(MockitoCore.java:59)
	at org.mockito.Mockito.mock(Mockito.java:1258)
	at org.mockito.internal.configuration.MockAnnotationProcessor.process(MockAnnotationProcessor.java:33)
	at org.mockito.internal.configuration.MockAnnotationProcessor.process(MockAnnotationProcessor.java:16)
	at org.mockito.internal.configuration.DefaultAnnotationEngine.createMockFor(DefaultAnnotationEngine.java:43)
	at org.mockito.internal.configuration.DefaultAnnotationEngine.process(DefaultAnnotationEngine.java:66)
	at org.mockito.internal.configuration.InjectingAnnotationEngine.processIndependentAnnotations(InjectingAnnotationEngine.java:71)
	at org.mockito.internal.configuration.InjectingAnnotationEngine.process(InjectingAnnotationEngine.java:55)
	at org.mockito.MockitoAnnotations.initMocks(MockitoAnnotations.java:108)
	at com.wfs.otc.lifecyclemanager.DataPersistorTest.setup(DataPersistorTest.java:89)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:497)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: org.apache.logging.log4j.core.config.ConfigurationException: No appenders are available for AsyncAppender Async
	at org.apache.logging.log4j.core.appender.AsyncAppender.start(AsyncAppender.java:106)
	at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:168)
	at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:359)
	at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:420)
	at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:138)
	at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:207)
	at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:41)
	at org.apache.logging.log4j.LogManager.getContext(LogManager.java:160)
	at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:492)
	at com.wfs.otc.lifecyclemanager.OptionExpiryDataHelper.<clinit>(OptionExpiryDataHelper.java:36)
	... 42 more

Solution: There could multiple reason this exception occurs. Below are some:

  • There are duplicate log4j configuration in the project or inside the dependent jar you are using
  • No appenders added in log4j file
  • If appenders are added correctly then two or more log4j configuration are clashing

In my case, this was happening due to two log4j2.xml file was configured. One was inside my main project and other was coming from dependencies jar I download from other project.

For more information please visit Log4j details documentation here

Leave a Reply

Your email address will not be published. Required fields are marked *