This week's book giveaway is in the Reactive Progamming forum.
We're giving away four copies of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams and have Adam Davis on-line!
See this thread for details.
Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

log4j not working with JUnit

 
Barry Andrews
Ranch Hand
Posts: 529
C++ Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I have a very strange problem. I hope someone else has seen this before. I have a class that uses log4j, and it works fine if I run the class by itself. I use PropertyConfigurator.configure("MyFile.ini"); However, if I run JUnit on this class, I get tons of errors like this:

If I use BasicConfigurator.confiure() in the tested class, then JUnit will run it just fine.
Very strange! Has anyone seen this problem before?
Many thanks to you,
Barry
 
Brian Buckley
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am seeing the identical problem. If anyone knows areason, a solution or a workaround, please post.
Brian
 
Calvin Robol
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a workaround that will work with log4j, however it requires you to rebuild/re-jar JUnit.
In the junit.jar, there is a file called excluded.properties. This lists all the packages you want to exclude from the Junit custom class loader, which I believe is causing the problem with log4j. Just add excluded.9=org.apache.log4j.*
to the list, rebuild junit, and log4j should work fine within your junit tests.
 
Olaf Kittelmann
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just used the workaround and now the
error with the double class loader is gone.
however, my log4j output is also gone.
I stepped through the log4j code and found that it tries to apply INFO level for my class although the rootlogger and the class explicitly are set to DEBUG level in the logger properties.
I helped myself with system.out statements, but
I am not really happy about it.
thanks,
Olaf
[ January 23, 2003: Message edited by: Olaf Kittelmann ]
 
Henrik Bladh
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've had the same problem and I solved it by passing "-Dlog4j.ignoreTCL=true" to the jvm.
http://www.mail-archive.com/log4j-dev@jakarta.apache.org/msg02425.html
 
That is a really big piece of pie for such a tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!