Example log4j.properties file
Posted by davidnewcomb on 01 Oct 2015 in Java
Configuring the Log4J properties file is one of those tasks which you have to spend a while trying to figure out but you invariably end up with the same thing. In fact most of the time something you cut and paste from the internet will do just fine. So here's mine!
This configuration outputs lines to a file and stdout.
# Root logger option
log4j.rootLogger=INFO, stdout, file
# Direct log messages to a log file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
log4j.appender.file.File=logs/my-app.0.0.log
log4j.appender.file.MaxFileSize=10MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
Example output:
2015-10-01 09:54:52 INFO ShortClassName:lineno - message
No feedback yet
Form is loading...