When you try to run a program that does logging from within Eclipse, have you ever seen this:
log4j:WARN No appenders could be found for logger (com.greymatter.MyClass).
log4j:WARN Please initialize the log4j system properly.
This happens because Log4j can't find its .properties file, so it can't configure its appenders, so you don't get any logging information. Here's how to fix this…
- In Eclipse, in one of the several places where you can find this, select either Run… or Debug… (Your change will apply to both types of program execution.)
- In the tree view on the left, select the Configuration you'd like to run with logging enabled.
- Click on the Classpath tab along the top.
- Click on the User Entries item in the tree view to select it.
- Click the Advanced… button.
- Select the Add Classpath Variables radio button, and click OK.
- If you see LOG4J_PROPS in the list of variables, select it and click OK. If it is not in the list, click the Configure Variables button. Add a Classpath Variable named LOG4J_PROPS with a value of the absolute path to the folder that contains the log4j.properties file. Once you've completed this process of adding the new variable, you will of course need to select it as you would have done if it had already existed.
- Click Apply to save your changes.
That's it! You should now be able to run or debug your app in Eclipse and have log4j configure properly. Ain't life grand?!
Revised January 17, 2005