Log4j的使用和怎么在spring中集成log4j

 我来答
匿名用户
2017-05-22
展开全部
web.xml引入log4j并启动
<!-- log4j配置,文件路径,因为是跟随项目启动 -->
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:log4j.properties</param-value>
</context-param>
<!-- 配置log4j.xml变量,如果需要动态的就使用下面方式,使用方法${name} -->
<context-param>
<param-name>controller</param-name>
<param-value>controller-log</param-value>
</context-param>

<context-param>
<param-name>loggingLevel</param-name>
<param-value>info</param-value>
</context-param>

<servlet>
<servlet-name>InitLog4jServlet</servlet-name>
<servlet-class>com.gta.common.program.InitLog4jServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<!-- 加载log4j配置文件 -->
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
log4j.properties使用即可
# default properties to initialise log4j
log4j.rootLogger=DEBUG, ERROR, console, file, errorLogTofile

# Console appender
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss.SSS} [%-5p] [%t] %c{1} - %m%n
log4j.throwableRenderer=org.apache.log4j.EnhancedThrowableRenderer

# File appender will print debug level log to the logs/debug.log
log4j.appender.file = org.apache.log4j.RollingFileAppender
log4j.appender.file.File =${webapp.root}/logs/debug.log
log4j.appender.file.Append =true
log4j.appender.file.MaxFileSize=100KB
log4j.appender.file.MaxBackupIndex=2
log4j.appender.file.Threshold=DEBUG
log4j.appender.file.layout = org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n

# File appender will print error level log to the logs/error.log
log4j.appender.errorLogTofile = org.apache.log4j.RollingFileAppender
log4j.appender.errorLogTofile.File =${webapp.root}/logs/error.log
log4j.appender.errorLogTofile.Append = true
log4j.appender.errorLogTofile.MaxFileSize=100KB
log4j.appender.errorLogTofile.MaxBackupIndex=2
log4j.appender.errorLogTofile.Threshold=ERROR
log4j.appender.errorLogTofile.layout = org.apache.log4j.PatternLayout
log4j.appender.errorLogTofile.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n

### print sql
log4j.logger.com.gta.common.program=DEBUG
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式