Spring Framework Logging
来源:互联网 发布:网络被骗2000报警么 编辑:程序博客网 时间:2024/06/07 04:05
Reference URL: http://docs.spring.io/spring-framework/docs/current/spring-framework-reference/html/overview.html
spring-core depend explicitly on commons-logging.
commons-logging has a runtime discovery algorithm that looks for other logging frameworks in well known places on the classpath
and uses one that it thinks is appropriate (or you can tell it which one if you need to).
If nothing else is available you get pretty nice looking logs just from the JDK (java.util.logging or JUL for short).
Unfortunately, the runtime discovery algorithm in commons-logging is problematic.
There are basically two ways to switch off commons-logging:
a. Exclude the dependency from the spring-core module (as it is the only module that explicitly depends on commons-logging)
b. Depend on a special commons-logging dependency that replaces the library with an empty jar.
the Simple Logging Facade for Java ( SLF4J) is a better alternative to commons-logging.
SLF4J is a cleaner dependency and more efficient at runtime than commons-logging
because it uses compile-time bindings instead of runtime discovery of the other logging frameworks it integrates.
To use SLF4J with Spring you need to replace the commons-logging dependency with the SLF4J-JCL bridge.
A common choice might be to bridge Spring to SLF4J, and then provide explicit binding from SLF4J to Log4J.
You need to supply 4 dependencies (and exclude the existing commons-logging):
the bridge, the SLF4J API, the binding to Log4J, and the Log4J implementation itself.
Additionally, provide it with a configuration file ( log4j.properties or log4j.xml in the root of the classpath).
POM.XML
<dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>4.1.6.RELEASE</version> <exclusions> <exclusion> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>jcl-over-slf4j</artifactId> <version>1.5.8</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.5.8</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>1.5.8</version> </dependency> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.14</version> </dependency></dependencies>
- Spring Framework Logging
- 【Spring.Framework】依赖管理, Logging
- GWT - Logging Framework
- POCO库的Logging framework
- POCO库的Logging framework
- Logging and Spring AOP
- Java自带的logging framework
- Spring framework
- Spring Framework
- Spring Framework
- Spring Framework
- Spring Framework
- Spring Framework
- Spring Framework
- Spring framework
- Spring Framework
- spring framework
- Spring framework
- Files类的简单使用-代码优雅之道Guava(二)
- 细说Session
- How To Defeat Advanced Malware. New Tools for Protection and Forensics
- Java抽象类与接口
- 伪列
- Spring Framework Logging
- PowerPC架构相比于ARM的优势
- 2. linux文件的分类与目录的分类
- 五大常用算法之二:动态规划算法
- Java如何传参数到main中
- pring事务管理(注解式声明事务管理)
- R语言基础编程技巧汇编 - 23
- vector::resize
- eclipse 插件安装