views:

199

answers:

3

What is the easiest way to get started with log4j configuration?

+4  A: 

Put a file named log4j.properties in the root of your classpath:

log4j.rootLogger = ALL, Console
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
log4j.appender.Console.layout.conversionPattern=%m%n

Nothing else is needed. Log4j will discover it and configure itself.

flybywire
+4  A: 

It's worth reading the manual (at the risk of stating the obvious). There are a ton of configuration options, and once you learn and understand what's possible, then you can implement some very powerful logging systems.

Brian Agnew
+5  A: 

The absolute easiest way is to visit the log4j pages at apache and read the short introduction. They have a sample log4j.configuration ready to be copied and pasted.

Andreas_D