-
导入log4j的jar包
-
在web.xml上配置如下:
<!-- 配置log4j begin --> < context-param > < param-name >webAppRootKey</ param-name > < param-value >bjgjqrcode.root</ param-value > <!-- .root --> </ context-param > < context-param > < param-name >log4jConfigLocation</ param-name > < param-value >WEB-INF/log4j.properties</ param-value > <!-- 配置文件存放路径 --> </ context-param > < listener > < listener-class > org.springframework.web.util.Log4jConfigListener </ listener-class > </ listener > <!-- 配置log4j end --> |
3. log4j.properties 文件配置如下:
log4j.rootLogger = DEBUG,console,E,I,D
#log4j.appender.file.DatePattern = yyyy-MM-dd‘.log‘
#debug message do not output to the file.
#output message in console
log4j.appender.console = org.apache.log4j.ConsoleAppender
log4j.appender.console.layout = org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern = [%-5p][%-22d{yyyy/MM/dd HH\:mm\:ssS}][%l]%n%m%n
log4j.appender.console.Threshold = DEBUG
log4j.appender.console.ImmediateFlush = TRUE
log4j.appender.console.Target = System.out
log4j.appender.E = org.apache.log4j.DailyRollingFileAppender
log4j.appender.E.layout = org.apache.log4j.PatternLayout
log4j.appender.E.layout.ConversionPattern = [%-5p][%-22d{yyyy/MM/dd HH\:mm\:ssS}][%l]%n%m%n
log4j.appender.E.Threshold = ERROR
log4j.appender.E.Append = TRUE
log4j.appender.E.File = ${bjgjqrcode.root}/WEB-INF/logs/running_error.log
log4j.appender.E.DatePattern = ‘.‘yyyy-MM-dd‘.log‘
log4j.appender.E.Encoding = UTF-8
log4j.appender.I = org.apache.log4j.DailyRollingFileAppender
log4j.appender.I.layout = org.apache.log4j.PatternLayout
log4j.appender.I.layout.ConversionPattern = [%-5p][%-22d{yyyy/MM/dd HH\:mm\:ssS}][%l]%n%m%n
log4j.appender.I.Threshold = INFO
log4j.appender.I.Append = TRUE
log4j.appender.I.File = ${bjgjqrcode.root}/WEB-INF/logs/running_info.log
log4j.appender.I.DatePattern = ‘.‘yyyy-MM-dd‘.log‘
log4j.appender.I.Encoding = UTF-8
log4j.appender.D = org.apache.log4j.DailyRollingFileAppender
log4j.appender.D.layout = org.apache.log4j.PatternLayout
log4j.appender.D.layout.ConversionPattern = [%-5p][%-22d{yyyy/MM/dd HH\:mm\:ssS}][%l]%n%m%n
log4j.appender.D.Threshold = DEBUG
log4j.appender.D.Append = TRUE
log4j.appender.D.File = ${bjgjqrcode.root}/WEB-INF/logs/running_debug.log
log4j.appender.D.DatePattern = ‘.‘yyyy-MM-dd‘.log‘
log4j.appender.D.Encoding =UTF-8