Log4j – log4j.properties examples
Published: December 31, 2009 , Updated: December 31, 2009 , Author: mkyong
I cant find many Log4j’s “log4j.properties” examples, here are few “log4j.properties” examples that are using in my project, just share it.
Output to Console
All the logging will redirect to your console
# Root logger option log4j.rootLogger=INFO, stdout # Direct log messages to stdout 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{ABSOLUTE} %5p %c{1}:%L - %m%n
Output to File
All the logging will redirect to your specified log file
# Root logger option log4j.rootLogger=INFO, file # Direct log messages to a log file log4j.appender.file=org.apache.log4j.RollingFileAppender log4j.appender.file.File=C:\\loging.log log4j.appender.file.MaxFileSize=1MB log4j.appender.file.MaxBackupIndex=1 log4j.appender.file.layout=org.apache.log4j.PatternLayout log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
Output to Console and File
All the logging will redirect to your specified log file and console
# Root logger option log4j.rootLogger=INFO, file, stdout # Direct log messages to a log file log4j.appender.file=org.apache.log4j.RollingFileAppender log4j.appender.file.File=C:\\loging.log log4j.appender.file.MaxFileSize=1MB log4j.appender.file.MaxBackupIndex=1 log4j.appender.file.layout=org.apache.log4j.PatternLayout log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n # Direct log messages to stdout 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{ABSOLUTE} %5p %c{1}:%L - %m%n
Reference
http://logging.apache.org/log4j/1.2/manual.html






*** Please give a simple example to integrate Spring and Log4j ***
OK i will give you ..
[...] 2. Log4j Appender Create a text file named “log4j.properties“, put it at the root of the project classpath. The log4j.properties or appender file is the Log4j configuration file, it defines how the Log4j logging mechanism work. See more Log4j appender examples. [...]
[...] log4j.properties examples – http://www.mkyong.com/logging/log4j-log4j-properties-examples/ [...]
hi there,
thanks for the post.
Google can be a good example for searching for a file type with an extension.
You can type “log4j.properties filetype:properties” into the google search box(without the quotes) and you will get quite a few matches.
example
BR,
~A
Hi, nice info, thanks for the tips :)