简体   繁体   中英

Output Log4J to file not working

I have read several times through the Log4J documentation and I am currently testing an example given by mkyong , but no matter what I do, Log4J keeps placing the output on my console.

This is the current file:

# DRAGONS AHEAD 
# Root logger option
log4j.rootLogger=debug, file

# Direct log messages to a log file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=/home/pedro/Desktop/log4j.txt
log4j.appender.file.MaxFileSize=1MB
log4j.appender.file.MaxBackupIndex=1
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

# END

# Print the date in ISO 8601 format
log4j.appender.stdout.layout.ConversionPattern=%d [%t] %-5p %c - %m%n

log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=application.log

log4j.appender.R.MaxFileSize=100KB
# Keep one backup file
log4j.appender.R.MaxBackupIndex=1

log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n

I keep thinking that I am doing something wrong, but I just cannot see what it can be. Can someone help me find what I am doing wrong?

Are you very sure that this property file is loaded in run time. You can loop through the loggers/appenders in runtime to see whether this configuration is loaded or not.

The only suggestion i have is to check the way you initialize log4j. Are you using BasicConfigurator.configure(); ?? Then your property settings wont get loaded.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM