Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

log4j sample configuration file (properties file)

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

like image 562
flybywire Avatar asked Jan 24 '10 18:01

flybywire


People also ask

What is the name of the log4j properties configuration file?

The log4j. properties file is a log4j configuration file which keeps properties in key-value pairs. By default, the LogManager looks for a file named log4j. properties in the CLASSPATH.

Can we use log4j without properties file?

println() over Log4j, of course for testing purposes, because it doesn't require any configuration, you can just use it, without bothering about XML or properties file configuration, but the most programmer will agree that they would prefer to use Log4j over println statements, even for test programs if it's easy to ...

Can log4j2 use log4j properties file?

Log4j 2 doesn't support the Log4j v1 ". properties" format anymore (yet, since v2. 4, Log4j supports a Property format, but its syntax is totally different from v1 format). New formats are XML, JSON, and YAML, see the documentation (note: if you used one of these formats in a file called ".


1 Answers

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.

like image 153
flybywire Avatar answered Oct 05 '22 23:10

flybywire