torsdag den 8. marts 2007

Quick taming of log4j

When beginning to create a new application using log4j the dreaded

log4j:WARN No appenders could be found for logger (....).
log4j:WARN Please initialize the log4j system properly.

quickly shows up. Instead of adding lines with BasicConfigurator, just create a file named "log4j.properties" in your source folder in Eclipse with the following content:

log4j.rootCategory=INFO, CONSOLE

log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
(note the ConversionPattern should go on a single line).

Instant gratification :D

Ingen kommentarer: