log4j 配置
log4j.properties
log4j.rootLogger=INFO,console,logfile
#输出信息到控制抬
log4j.APPender.console = org.apache.log4j.Consoleappender
log4j.appender.console.Target = System.out
log4j.appender.console.layout = org.apache.log4j.PatternLayout
log4j.appender.console.layout.conversionpattern = [%-5p] %d{yyyy-MM-dd HH:mm:ss} %m%n
#输出到文件
log4j.appender.logfile=org.apache.log4j.FileAppender
log4j.appender.logfile.File=F:/logger.log
log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
log4j.appender.logfile.layout.ConversionPattern= [%-5p] %d{yyyy-MM-dd HH:mm:ss} %m%n
使用
private static final Logger logger=Logger.getLogger(Demo.class);