Spring Boot中slf4j日志依赖关系?相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。
成都创新互联公司从2013年成立,是专业互联网技术服务公司,拥有项目成都网站设计、做网站网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元靖西做网站,已为上家服务,为靖西各地企业和个人服务,联系电话:18982081108
底层依赖关系
关系如何转化
底层通过偷梁换柱的方法,用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
看完上述内容,你们掌握Spring Boot中slf4j日志依赖关系的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注创新互联行业资讯频道,感谢各位的阅读!
网站标题:SpringBoot中slf4j日志依赖关系
文章位置:https://www.cdcxhl.com/article36/gghesg.html
成都网站建设公司_创新互联,为您提供自适应网站、网站收录、、外贸网站建设、Google、App设计
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联