日志文件为空(log4j) [英] Log file is empty (log4j)
本文介绍了日志文件为空(log4j)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
日志信息显示在控制台上,而不显示在日志文件上(已创建文件,但未添加任何内容).怎么了?
Log information is shown on console but not on the log file (the file is created but no content is added). What's wrong?
来源:
package mytest;
import java.util.logging.Level; import java.util.logging.Logger;
import org.apache.log4j.PropertyConfigurator;
public class Main {
public static void main(String[] args) {
Logger log = Logger.getLogger(Main.class.getName());
log.setLevel(Level.ALL);
log.info("A line)");
PropertyConfigurator.configure("log.properties");
log.info("Another line");
}
}
log.properties文件:
log4j.rootLogger=debug, stdout, R
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=example.log
log4j.appender.R.MaxFileSize=100KB
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n
推荐答案
您正在混合使用java.util.logging和log4j.
You are mix things, java.util.logging and log4j.
您可以尝试将commonsLoggin与log4j一起使用
You can try to use commonsLoggin with log4j
http://commons.apache.org/logging/guide.html# Quick%20Start
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
...
Log log = LogFactory.getLog(getClass());
这篇关于日志文件为空(log4j)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文