Log4j使用--简单配置
来源:互联网 发布:北京seo学校哪家好 编辑:程序博客网 时间:2024/05/16 06:35
在web.xml文件中增加如下配置:
<?xml version="1.0"?>
<!--
* Copyright 2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
-->
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<servlet>
<servlet-name>log4j</servlet-name>
<servlet-class>org.springframework.web.util.Log4jConfigServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<context-param>
<param-name>webAppRootKey</param-name>
<param-value>BBS.root</param-value>
</context-param>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/classes/log4j.properties</param-value>
</context-param>
<context-param>
<param-name>log4jRefreshInterval</param-name>
<param-value>60000</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
</web-app>
<!--
* Copyright 2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
-->
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<servlet>
<servlet-name>log4j</servlet-name>
<servlet-class>org.springframework.web.util.Log4jConfigServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<context-param>
<param-name>webAppRootKey</param-name>
<param-value>BBS.root</param-value>
</context-param>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/classes/log4j.properties</param-value>
</context-param>
<context-param>
<param-name>log4jRefreshInterval</param-name>
<param-value>60000</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
</web-app>
log4j.properties配置(按照个人需要配置日志级别):
log4j.rootLogger=DEBUG,CONSOLE
log4j.addivity.org.apache=true
# ??????
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.Threshold=DEBUG
log4j.appender.CONSOLE.Target=System.out
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=[framework] %d - %c -%-4r [%t] %-5p %c %x - %m%n
#log4j.appender.CONSOLE.layout.ConversionPattern=[start]%d{DATE}[DATE]%n%p[PRIORITY]%n%x[NDC]%n%t[THREAD] n%c[CATEGORY]%n%m[MESSAGE]%n%n
log4j.addivity.org.apache=true
# ??????
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.Threshold=DEBUG
log4j.appender.CONSOLE.Target=System.out
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=[framework] %d - %c -%-4r [%t] %-5p %c %x - %m%n
#log4j.appender.CONSOLE.layout.ConversionPattern=[start]%d{DATE}[DATE]%n%p[PRIORITY]%n%x[NDC]%n%t[THREAD] n%c[CATEGORY]%n%m[MESSAGE]%n%n
之后将Log4j.jar加入到项目中,就可以在类中使用Log4j了:)
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class TestLog4j...{
private Log log=LogFactory.getLog(this.getClass());
public static void main(String[] args) ...{
if(log.isDebugEnabled())...{
log.debug("Test log4j");
}
}
}
import org.apache.commons.logging.LogFactory;
public class TestLog4j...{
private Log log=LogFactory.getLog(this.getClass());
public static void main(String[] args) ...{
if(log.isDebugEnabled())...{
log.debug("Test log4j");
}
}
}
- Log4j使用--简单配置
- Log4j的简单配置使用!
- Log4j的简单配置使用!
- Log4j的简单配置使用
- log4j--------简单配置与使用
- log4j的配置以及简单使用
- log4j 的简单配置与使用
- Log4j配置使用的简单教程
- log4j和log4j2的简单使用配置
- log4j日志简单配置及使用
- 简单介绍Log4J的使用和Spring 配置log4j
- Spring 配置log4j和简单介绍Log4J的使用
- Spring 配置log4j和简单介绍Log4J的使用
- Spring 配置log4j和简单介绍Log4J的使用
- Spring 配置log4j和简单介绍Log4J的使用
- Spring 配置log4j和简单介绍Log4J的使用
- log4j配置简单说明
- Log4j 简单配置
- 忘记WinXP系统登陆密码解决办法!
- 子窗体和父窗体交互
- AJAX初始的开发框架
- JSP中判断session time out
- ajax资源网址收藏
- Log4j使用--简单配置
- Asp.net'Atlas'初次学习大纲
- 最近要放出来的一个小lib BugReport
- 《英雄连》导致机器诡异死机……
- 手机短信服务接口合作协议原理与分析
- 字符转义技术
- 关于CString总结
- 数据结构你懂多少?
- 也谈谈某些见解,我的笔记本终于可以使用了