If you have ever developed a JAVA project inside eclipse and used a log4j logger, you might have reached a point where you get error message such as the following one when you tried to run the program or a unit test against it:

log4j:WARN No appenders could be found for logger (foo.bar.Class).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

This happens especially if you are developing a component that assumes the environment it runs in to take care for the log4j configuration and does not use it’s own one.

You can solve this problem by following the steps described below:

1. First, create a file named log4j.properties with the following content

log4j.rootCategory=TRACE, CONSOLE
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.Threshold=INFO
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=- %m%n

2. Make a zip archive of this file and rename it to jar “log4jprops.jar” and store it somewhere on your file system. Using a subdirectory of your workspace is recommended (e.g., /workspace/configuration/log4jprops.jar).
3. In Eclipse, go to Window -> Preferences -> Java -> Build Path -> Class Path Variables
4. Create a new Variable named LOG4J_PROPS and point it to the jar file created before.
5. Go to the run configuration you would like to use this configuration for
6. Open the Classpath Tab, Select User Entries, Click Advanced, Select Add Classpath Variables, Click ok and select the variable created before
7. Just run your configuration and there you go…

Eclipse Log4J Properties for the Whole Workspace

Post navigation


Leave a Reply