好用的log4j.properties配置文件(按照级别打印日志,每天生成不同类型的日志,可以打印sql日志)
日志按照级别分类
log4j.rootLogger = INFO,stdout,D,E,I #ShuChuDaoDaYingTai log4j.appender.stdout = org.apache.log4j.ConsoleAppender log4j.appender.stdout.Target = System.out log4j.appender.stdout.layout = org.apache.log4j.PatternLayout #log4j.appender.stdout.layout.ConversionPattern = [%-5p] %d{yyyy-MM-dd HH:mm:ss,SSS} method:%l%n%m%n log4j.appender.stdout.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss.SSS} %l -%m%n #log4j.appender.stdout.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss.SSS} %p %c -%m%n #DEBUG log4j.appender.D = org.apache.log4j.DailyRollingFileAppender log4j.appender.D.File =${env.log4j.logfile}/webDebug.log log4j.appender.D.File.DatePattern='.'yyyy-MM-dd log4j.appender.D.Append = true log4j.appender.D.Threshold = DEBUG log4j.appender.D.layout = org.apache.log4j.PatternLayout #log4j.appender.D.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss.SSS} [ %t:%r ] - [ %p ] %m%n log4j.appender.D.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss.SSS} %l -%m%n #ERROR log4j.appender.E = org.apache.log4j.DailyRollingFileAppender log4j.appender.E.File =${env.log4j.logfile}/webError.log log4j.appender.E.File.DatePattern='.'yyyy-MM-dd log4j.appender.E.Append = true log4j.appender.E.Threshold = ERROR log4j.appender.E.layout = org.apache.log4j.PatternLayout log4j.appender.E.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss.SSS} %l -%m%n #log4j.appender.E.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss.SSS} [ %t:%r ] - [ %p ] %m%n #INFO log4j.appender.I = org.apache.log4j.DailyRollingFileAppender log4j.appender.I.File =${env.log4j.logfile}/webInfo.log log4j.appender.I.File.DatePattern='.'yyyy-MM-dd log4j.appender.I.Append = true log4j.appender.I.Threshold = INFO log4j.appender.I.layout = org.apache.log4j.PatternLayout log4j.appender.I.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss.SSS} %l %m%n
还可以在下面加入打印运行sql的日志
log4j.rootLogger=DEBUG,Console #Console 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=%d [%t] %-5p [%c] - %m%n log4j.logger.org.apache=ERROR log4j.logger.org.mybatis=ERROR log4j.logger.org.springframework=ERROR #\u8FD9\u4E2A\u9700\u8981 log4j.logger.log4jdbc.debug=ERROR log4j.logger.com.gk.mapper=ERROR log4j.logger.jdbc.audit=ERROR log4j.logger.jdbc.resultset=ERROR #\u8FD9\u4E2A\u6253\u5370SQL\u8BED\u53E5\u975E\u5E38\u91CD\u8981 log4j.logger.jdbc.sqlonly=DEBUG log4j.logger.jdbc.sqltiming=ERROR
一定要爱着点儿什么,恰似草木对光阴的钟情。