Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

log4j:ERROR A "org.apache.log4j.ConsoleAppender" object is not assignable to a "org.apache.log4j.Appender" variable

I am making a web app using gradle. I used log4j in this app. When I build the project I am getting error...

  • log4j:ERROR A "org.apache.log4j.ConsoleAppender" object is not assignable to a "org.apache.log4j.Appender" variable.
  • log4j:ERROR The class "org.apache.log4j.Appender" was loaded by
  • log4j:ERROR [org.powermock.core.classloader.MockClassLoader@16a40b2] whereas object of type
  • log4j:ERROR "org.apache.log4j.ConsoleAppender" was loaded by [sun.misc.Launcher$AppClassLoader@5e3a78ad].
  • log4j:ERROR Could not instantiate appender named "stdout".

I still did not find a good answer. And I forgot to say, My project build correctly and show log massages correctly. It doesn't work only on test classes.

like image 397
Kasun Kariyawasam Avatar asked Jan 13 '14 11:01

Kasun Kariyawasam


3 Answers

Adding this annotation works for me.

@PowerMockIgnore("org.apache.log4j.*") 
like image 100
ToYonos Avatar answered Oct 03 '22 11:10

ToYonos


Your classpath contains 2 copies of log4j library. Exclude one and try again.

like image 22
artplastika Avatar answered Oct 03 '22 11:10

artplastika


There is a Clear answer here. :D

When we have a final method and slf4j loggers in our classes. We have to use powermock in our test class. Because of this we have to use @MockPolicy(Slf4jMockPolicy.class) with particuler imports at the test class which we used Powermock.

like image 45
Kasun Kariyawasam Avatar answered Oct 03 '22 11:10

Kasun Kariyawasam