Controlling your log4j settings

Nick over at the System Mobile Web Log was having trouble with Log4J and his unit tests. Seems that he was getting the log4j.properties file from XDoclet, instead of the one he wanted.

Getting Log4J to pick up the right configuration file via the classpath is always annoying. Fortunately, there’s an easy solution.

All you need to do is specify the log4j.configuration system property when you launch JUnit. The value should be the path to the log4j.properties or log4j.xml file you wish to use. Here’s an example:











To quote Nick: Hopefully this helps somebody else.

Author: Robert Watkins

My name is Robert Watkins. I am a software developer and have been for over 20 years now. I currently work for people, but my opinions here are in no way endorsed by them (which is cool; their opinions aren’t endorsed by me either). My main professional interests are in Java development, using Agile methods, with a historical focus on building web based applications. I’m also a Mac-fan and love my iPhone, which I’m currently learning how to code for. I live and work in Brisbane, Australia, but I grew up in the Northern Territory, and still find Brisbane too cold (after 22 years here). I’m married, with two children and one cat. My politics are socialist in tendency, my religious affiliation is atheist (aka “none of the above”), my attitude is condescending and my moral standing is lying down.

Leave a comment