日志信息显示在控制台上,但不在日志文件上(文件已创建但未添加内容)。怎么了?
资源:
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