内容简介:底层依赖关系关系如何转化底层通过偷梁换柱的方法,用jcl、jul、log4j中间转换包进行转化
SpringBoot 底层使用的是 slf4j+logback 来进行日志记录
- 把其他
common-logging、log4j、java.util.logging转换为slf4j
底层依赖关系
关系如何转化
底层通过偷梁换柱的方法,用jcl、jul、log4j中间转换包进行转化
如果要引入其他框架,必须将其中默认日志依赖剔除
SpringBoot 从maven依赖中剔除 springframework:spring-core 中的 common-logging
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.3.20.RELEASE</version>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency>
复制代码
+++
SpringBoot 默认日志级别为 INFO 级别
- 日志优先级从小到大顺序为:
-
trace<debug<info<warn<error
-
package com.example.demo;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class DemoApplicationTests {
Logger log = LoggerFactory.getLogger(getClass());
@Test
public void contextLoads() {
log.trace("trace日志");
log.debug("debug日志");
log.info("info日志");
log.warn("warn日志");
log.error("error日志");
}
}
复制代码
- 启动运行,控制台打印只打印了
info及以上级别
2018-11-09 00:13:36.899 INFO 8156 --- [main] com.example.demo.DemoApplicationTests : info日志 2018-11-09 00:13:36.900 WARN 8156 --- [main] com.example.demo.DemoApplicationTests : warn日志 2018-11-09 00:13:36.900 ERROR 8156 --- [main] com.example.demo.DemoApplicationTests : error日志 复制代码
日志基础配置
# 指定日志输入级别
logging.level.com.example.demo=trace
# 指定日志输出位置和日志文件名
logging.file=./log/log.txt
# 指定日志输出路径,若file和path同时配置,则file生效
# 此配置默认生成文件为spring.log
#logging.path=./log
# 控制台日志输出格式
# -5表示从左显示5个字符宽度
logging.pattern.console=%d{yyyy-MM-dd HH:mm:ss.SSS} %highlight(%-5level) %boldYellow(%thread) | %boldGreen(%logger) | %msg%n
# 文件中输出的格式
logging.pattern.file=%d{yyyy-MM-dd HH:mm:ss.SSS} = [%thread] = %-5level = %logger{50} - %msg%n
复制代码
以上所述就是小编给大家介绍的《SpringBoot 中的 slf4j 日志依赖关系》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
猜你喜欢:- Bundler 2.0 发布,RubyGems 依赖关系管理工具
- Bundler 2.0 发布,RubyGems 依赖关系管理工具
- 基于关系数据库的数据库功能依赖性
- Spring中循环依赖的正确性与Bean注入的顺序关系
- jQuery 3.3.1 发布,修复 3.3.0 版本中的依赖关系
- Spring Cloud Task 2.0.0 发布,升级了所有的依赖关系
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Sprint
Jake Knapp、John Zeratsky、Braden Kowitz / Simon & Schuster / 2016-3-8 / GBP 14.60
媒体推荐 “Every business leader I know worries about the same thing: Are we moving fast enough? The genius of Jake Knapp’s Sprint is its step-by-step breakdown of what it takes to solve big problems an......一起来看看 《Sprint》 这本书的介绍吧!