[Spring]在Spring中配置log4j
软件技术
lhwork 发表于 2006-8-4 10:00:02
首先需要在web.xml进行声明:
<!--如果不定义webAppRootKey参数,那么webAppRootKey就是缺省的"webapp.root"-->
<context-param>
<param-name>webAppRootKey</param-name>
<param-value>ssh.root</param-value>
</context-param>
这里的ssh是http://localhost:8080/ssh/
而root是系统开发目录中ssh/root
这样配置文件以及日志文件可以在spring的帮助下,放到开发环境中的任意位置
<!--由Sprng载入的Log4j配置文件位置-->
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/log4j.properties</param-value>
</context-param>
在这里定位配置文件,需要的是从root开始的绝对路径
<!--Spring默认刷新Log4j配置文件的间隔,单位为millisecond-->
<context-param>
<param-name>log4jRefreshInterval</param-name>
<param-value>60000</param-value>
</context-param>
<!--Spring log4j Config loader-->
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
设置监听器
/////////////////
之后我们就可以配置log4j配置文件了
#先设置级别
log4j.rootCategory=INFO, file
log4j.appender.file=org.apache.log4j.RollingFileAppender
#在这里设置日志需要存放的位置,这里的变量就是我们在web.xml里设置的
log4j.appender.file.File=${ssh.root}/WEB-INF/logs/subject.log
log4j.appender.file.MaxFileSize=100KB
log4j.appender.file.MaxBackupIndex=0
log4j.appender.file.layout=org.apache.log4j.SimpleLayout
log4j.appender.file.layout.ConversionPattern=[ssh] %p %t %c - %m%n
有了上面的配置,我们就可以查看日志了!
阅读全文(1272) | 回复(0) | 编辑 | 精华
分享到:
相关推荐
spring-mvc.xml spring-mybatis.xml web.xml log4j.properties,项目中需要用到的配置文件。直接可用。
config.properties:数据库配置文件 log4j.properties:mybatis日志文件 spring-mvc.xml:spring-MVC配置文件 spring-mybatis.xml:mybatis的配置文件 spring.xml
org.springframework.web.context.request.Log4jNestedDiagnosticContextInterceptor.class org.springframework.web.context.request.RequestAttributes.class org.springframework.web.context.request....
IDEA版整合ssm(Spring+SpringMVC+Mybatis)框架,学生增删改查基础项目。附带源码的log4j
在log4j.properties配置文件中可以指定字符编码: 下面这行配置指定了两个appender: log4j.rootCategory=INFO,appender1的名字,appender2的名字 下面这两行配置将上一行的两个appender的字符编码配置为GBK:
ssm一个简单项目所需的xml配置文件,spring+springmvc+mybatis框架中用到...项目中还会用到两个资源属性文件jdbc.properties和log4j.properties.一个是关于jdbc的配置,提取出来方便以后的修改.另一个是日志文件的配置.
1.创建web工程 2.导入jar spring-framework-2.5.6\dist\...spring-framework-2.5.6\samples\jpetstore\war\WEB-INF\log4j.properties spring-framework-2.5.6\samples\jpetstore\war \WEB-INF\applicationContext.xml
application.properties 配置如下 #静态文件配置 spring.webflux.static-path-pattern =classpath:/static/** #数据库配置 #spring.datasource.url =jdbc:mysql://localhost:3306/springboot?serverTimezone...
4.“定时器.txt”记录的是长链接链路检查的基于spring的配置,如果使用java原生定时器可自行配置。 5.依赖包包括log4j.jar、quartz-1.5.2.jar,quartz-1.5.2.jar为定时器使用,除此之外无特殊依赖包
客户端配置:##log4j.properties#####kafka topic名称log4j.appender.kafka.topic=log4jtest#####kafka broker地址log4j.appender.kafka.brokerList=Hadoop2-302E9-1-5:9092,Hadoop3-302E9-1-6:9092###配置完成后,...
20.2.4. Disabling Restart 20.2.5. Using a Trigger File 20.2.6. Customizing the Restart Classloader 20.2.7. Known Limitations 20.3. LiveReload 20.4. Global Settings 20.5. Remote Applications 20.5.1. ...
3、搭建Spring配置:spring.xml(扫描service),config.properties,log4j.properties; 4、搭建spring和mybatis的配置:spring-mybatis.xm(扫描dao)) 5、测试Spring+mybatis的框架搭建,写单元测试JUnit,测试事务配置...
文件中内容包括模块中某个类单独输出到一个日志文件中、模块中某个package单独输出到一个日志文件中、同一模块不同package输出到一个日志文件中三种情况下log4j.properties配置项配置事例、Java类中代码如何一致编写...
我java小白,自己摘抄,并一点点运行验证,并加注释解释,搞了半个月。 web.xml,spring-mvc.xml,applicationContext.xml,mybatis-config.xml,jdbc.properties,log4j.properties,pom.xml
spring日志文件打印配置: 1.所需jar包log4j-1.2.13.jar 2.配置log4j.properties
SSM框架rescoures的5个配置文件,有database.properties/log4j.properties/mybatis-config.xml/spring-mvc.xml/spring-mybatis.xml
ssm配置文件 web.xml applicationContext.xml mybatis-config.xml spring-mvc.xml jdbc.properties log4j.properties
All Classes ...Log4jNestedDiagnosticContextFilter Log4jWebConfigurer LookupDispatchActionSupport LookupOverride MailAuthenticationException MailException MailMessage MailParseException ...