准备工作:
开发工具:eclipse 或其他IDE
spring版本3.24下载地址:
Log4j版本:log4j-1.2.16.jar
1.创建一个动态web项目,名字任意指定
2.导入spring-framework-3.2.4.RELEASE\libs下以及log4j的jar包
spring-beans-3.2.4.RELEASE.jar
spring-context-3.2.4.RELEASE.jar
spring-core-3.2.4.RELEASE.jar
log4j-1.2.16.jar
2.在classpath(也就是src下)下创建在log4j包的log4j.properties 具体配置说明可以百度一下
log4j.rootCategory=INFO,stdout,R log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=[springLogger] %d{yyyy MMM dd HH:mm:ss,SSS} %p [%t] %C.%M(%L) %m%n log4j.appender.R=org.apache.log4j.DailyRollingFileAppender log4j.appender.R.File=${springLogger.root}/logs/logger.log log4j.appender.R.layout=org.apache.log4j.PatternLayout 1log4j.appender.R.layout.ConversionPattern=[springLogger] %d{yyyy MMM dd HH:mm:ss,SSS} %p [%t] %C.%M(%L) %m%n log4j.logger.org.springframework=DEBUG log4j.logger.org.apache.velocity=FATAL
在web.xml中配置内容:
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>springLogger</display-name> <!--如果不定义webAppRootKey参数,那么webAppRootKey就是缺省的"webapp.root"--> <context-param> <param-name>webAppRootKey</param-name> <param-value>springLogger.root</param-value> </context-param> <!-- log4j.properties 的路径 --> <context-param> <param-name>log4jConfigLocation</param-name> <param-value>classpath:log4j.properties</param-value> </context-param> <!-- 开一条watchdog线程每60秒扫描一下配置文件的变化 --> <context-param> <param-name>log4jRefreshInterval</param-name> <param-value>60000</param-value> </context-param> <!-- log4j的日志监听--> <listener> <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class> </listener> <context-param> <param-name>contextConfigLocation</param-name> <param-value> classpath:applicationContext.xml </param-value> </context-param> <listener> <!-- 在Spring2.0中除了以前的Singleton和Prototype外又加入了三个新的web作用域,分别为request、session和global session,如果你想让你的容器里的某个bean拥有其中某种新的web作用域,除了在bean级上配置相应的scope属性,还必须在容器级做一个额外的初始化配置 --> <listener-class> org.springframework.web.context.request.RequestContextListener </listener-class> </listener> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener> <welcome-file-list> <welcome-file>index.html</welcome-file> </welcome-file-list> </web-app>
在classpath(也就是src下)下创建 applicationContext.xml 资源文件,没有注入内容,只为测试
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd"> </beans>
在项目中com.test下创建一个Main.java类文件
package com.test; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.util.Assert; /** * @author HL Yang * @date 创建时间:2014年11月25日 下午4:09:30 */ public class Main { public static void main(String args[]) throws InterruptedException{ ApplicationContext ctx = new ClassPathXmlApplicationContext("classpath:applicationContext.xml"); Assert.isNull(ctx,"this ctx is not null "); } }
至此配置文件都已完成
需要注意的两点是:
<!--如果不定义webAppRootKey参数,那么webAppRootKey就是缺省的"webapp.root"-->
<context-param>
<param-name>webAppRootKey</param-name>
<param-value>springLogger.root</param-value>
</context-param>
可以与log4j.properties中log4j.appender.R.File=${springLogger.root}/logs/logger.log对应输出
相关推荐
Java日志全面示例,可以下载运行,简洁易懂,能说明问题。 用maven构建,Java中普通加载log4j,普通web项目加载log4j,Spring项目加载log4j,让你彻底清除Java日志的配置和集成
现在很流行springboot的开发,小编闲来无事也学了学,开发过程中遇见了log4j日志的一个小小问题,特此记载。 首先在pox.xml中引入对应的maven依赖: <!-- 引入log4j--> <groupId>org.springframework....
SpringMVC精品资源--Spring+Springmvc+Mybatis框架,后续集成日志插件log4j、lo
springmvc spring3 hibernate4 log4j 完整的注解配置 spring切面自动打日志等,需要自己建一个小表 可运行 并且已经将bootstrap集成进去.
本文主要介绍了在 Spring Boot 框架中如何使用 Log4j 和 Slf4j,并通过对比分析它们的优缺点,帮助读者更好地选择合适的日志记录工具。文章中提供了完整的示例代码,并附有详细的注释说明。 Log4j 和 Slf4j 都是...
对于日志来说,最常见的需求就是收集、存储、查询、展示,开源社区正好有相对应的开源项目:logstash(收集)、elasticsearch(存储+搜索)、kibana(展示),我们将这三个组合起来的技术称之为ELK,所以说ELK指的是...
SSM+cxf+log4j整合框架;springmvc+spring+mybatis整合开发,内部集成webservice技术,采用cxf框架进行实现,log4j进行日志记录
构建Spring+Springmvc+Mybatis框架,丰富框架的功能,后续集成日志插件log4j、logback,集成Druid连接池监控,集成Redis缓存,office文件操作插件poi等。 1.基于mvc实现基本的数据增删改查操作。 2.已经分别集成log4...
项目日志记录是项目开发、运营必不可少的内容,有了它可以对系统有整体的把控,出现任何问题都有踪迹可寻。下面这篇文章主要给大家介绍了关于Spring MVC项目中log4J和AOP使用的相关资料,需要的朋友可以参考下。
Log4j直接发送数据到Flume + Kafka (方式一) 通过flume收集系统日记, 收集的方式通常采用以下. 系统logs直接发送给flume系统, 本文主要记录种方式进行说明. 文章链接,请看:...
用sf4j及logback(log4j的升级版)记录日志;proxool(据说是dbcp和c3p0三者中最优秀的)做连接池;使用jquery的ajax实现仿google人名自动补全;头像上传剪切压缩处理。 包含有完整的jar包和源代码,可以直接下载...
SpringBoot WebService cxf接口发布以及logbok日志集成, 希望对学习的小伙伴们有帮助
本人搭建的ssm框架的maven web项目,用maven管理项目的jar包,项目架构搭好,用的都是现阶段最新的jar包,整合了log4j日志,redis缓存,quartz定时任务,全局配置文件在代码中使用等,controller层/service层/bo层/dao层都...
tags: [#springboot, #日志]1、默认实现的日志配置Spring boot默认已经集成了logging,同时也是默认开启的,如果想根据自己的需
日志 不使用通用日志 使用SLF4J 使用Log4j 二世。 什么是新的在春季3 2。 新特性和增强功能在Spring框架3.0 2.1。 Java 5 2.2。 改进文档 2.3。 新的文章和教程 2.4。 新模块的组织和构建系统 2.5。 概述的新特性 2...
主要介绍了Spring Boot2集成AOPLog来记录接口访问日志,日志是一个Web项目中必不可少的部分,借助它我们可以做许多事情,比如问题排查、访问统计、监控告警等,需要的朋友可以参考下
logback-classic:它是log4j的一个改良版本,同时它完整实现了slf4j API使你可以很方便地更换成其它日志系统如log4j或JDK14 Logging。 logback-access:访问模块与Servlet容器集成提供通过Http来访问日志的功能。 ...
Spring MVC 演示应用程序 此应用程序演示了使用 Spring MVC 和其他技术,如Hibernate、junit 和 log4j。... 您可以在 SpringMVCDemo/SpringMVC/src/main/resources/log4j.properties 文件中更改日志文件的位置。
Springmvc4.1.5+Spring4.1.5+Mybatis3.2.7+Maven的空项目,经过spring单元测试,log4j日志集成。
Example涵盖内容: 4种日志框架详解:Logback、Log4j、Log4j2和Slf4j,基于secure-ext-spring-boot-starter日志记录脱敏,spring-session基于redis存储session,集成MyBatis以及mybatis-plus3的应用实践,安全认证-...