edit this page - page history - about editing


Log4J is a logging framework for Java which can be quite a challenge to set up. Because it is based on files, rather than Java code, there is a lot of trickery and witchery needed to set it up.

Eclipse and Log4J

I have found a solution which is the easiest way to specify a log4j.properties configuration if you are running an Eclipse JUnit Plugin Test. Essentially, you create a basic log4j.properties like so:

# Set root logger level to DEBUG and its only appender to A1.
log4j.rootLogger=DEBUG, A1

# A1 is set to be a ConsoleAppender.

# A1 uses PatternLayout.
log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n

And instruct Log4j to use this file instead:

System.setProperty("log4j.configuration", "file:///" + new File("log4j.properties").getAbsolutePath());

Categories: Java | Eclipse
edit this page - what links to here? - page history - top
Last edited by jevon jevon 92 months ago