log4j jar版本: log4j-1.2.17.jar;
log对象: private static final Logger log = Logger.getLogger(DeliveryInfoAction.class);
log4j.properties配置如下
log4j.rootCategory=DEBUG,INFO,ERROR,ConApp,DailyFileApp1 ############################### #########display at console###################### log4j.appender.ConApp=org.apache.log4j.ConsoleAppender log4j.appender.ConApp.Threshold=DEBUG log4j.appender.ConApp.layout=org.apache.log4j.PatternLayout log4j.appender.ConApp.layout.ConversionPattern=%d{[yyyy-MM-dd HH\:mm\:ss]} [%t] %-5p %c - %m%n ######### DEBUG ###################### log4j.logger.com.ibatis = DEBUG log4j.logger.com.ibatis.common.jdbc.SimpleDataSource = DEBUG log4j.logger.com.ibatis.common.jdbc.ScriptRunner = DEBUG log4j.logger.com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate = DEBUG log4j.logger.java.sql.Connection = DEBUG log4j.logger.java.sql.Statement = DEBUG log4j.logger.java.sql.PreparedStatement = DEBUG log4j.logger.java.sql.ResultSet = DEBUG #########display at log file###################### log4j.appender.DailyFileApp1=org.apache.log4j.DailyRollingFileAppender log4j.appender.DailyFileApp1.Threshold=DEBUG log4j.appender.ROLLING_FILE.Append=true log4j.appender.DailyFileApp1.File=${catalina.home}/logs/j1-eai/daily-debug.log log4j.appender.DailyFileApp1.DatePattern='.'yyyy-MM-dd log4j.appender.DailyFileApp1.layout=org.apache.log4j.PatternLayout log4j.appender.DailyFileApp1.layout.ConversionPattern=%d{[yyyy-MM-dd HH:mm:ss]} [%t] %-5p %c - %m%n
现象:
(1)
log.debug(====debug====);//控制台无此打印记录,daily-debug.log日志文件无此记录
log.info(====info====);//控制台有此打印记录,daily-debug.log日志文件无此记录
log.warn(====warn====);//控制台有此打印记录,daily-debug.log日志文件无此记录
(2)
SQL语句在控制台有打印记录、但也没有写入daily-debug.log日志文件;若在log4j.properties中注释掉sql打印那一段配置,那么再次运行程序,在控制台不会有sql语句打印。
(3)
在日志文件daily-debug.log中只看到了项目启动信息记录。