springboot使⽤logback启动报警报错的解决
springboot logback启动报警报错
报错信息如下:
16:06:07,484 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [l]
16:06:07,484 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [vy]
16:06:07,485 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [l] at [file:/C:/Users/Administrator/Desktop/***/***/target/l]
16:06:07,638 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - debug attribute not set
16:06:07,646 |-INFO in ch.joran.action.AppenderAction - About to instantiate appender of type [ch.ConsoleAppender]
16:06:07,653 |-INFO in ch.joran.action.AppenderAction - Naming appender as [consoleAppender]
先说解决⽅法:
把⽇志⽂件名称改为-spring结尾就不报警了 l
tips(springboot⽇志使⽤logback):
Spring Boot官⽅推荐优先使⽤带有-spring的⽂件名作为你的⽇志配置(如使⽤l,⽽不是l),如果想⾃定义⽂件名,可以通过fig属性指定⾃定义的名字:
官⽅start包中已经默认集成了slf4j和logback不⽤导⼊任何⽇志依赖
推荐使⽤logback,性能优于log4j
设置logback彩⾊⽇志
<property name="solePattern" value="%highlight(%date{yyyy-MM-dd HH:mm:ss.SSS}) %boldY
ellow([%thread]) %highlight([%-5level])  %boldCyan([%replace(%caller{1}){'\t|Caller.{1}0|\r\n', ''}]) %msg%n"/>
<!-- 控制台设置,主要是上⽅pattern修改就可以,其他地⽅可以⽤不同pattern -->
<appender name="CONSOLE_APPENDER" class="ch.ConsoleAppender">
<encoder>
<pattern>${solePattern}</pattern>  <!-- 控制台⽇志输出格式 -->
<charset>utf8</charset>
</encoder>
</appender>
springboot多环境开发⽇志
<!-- 测试环境+开发环境. 多个使⽤逗号隔开 -->
<springProfile name="test,dev">
<logger name="⼯程包路径" level="info" />
</springProfile>
<!-- ⽣产环境. -->
<springProfile name="prod">
<logger name="⼯程包路径" level="ERROR" />
</springProfile>
<
/***
* _ooOoo_
* o8888888o
* 88" . "88
* (| -_- |)
*  O\ = /O
* ___/`---'\____
* .  ' \\| |// `.
* / \\||| : |||// \
* / _||||| -:- |||||- \
* | | \\\ - /// | |
* | \_| ''\---/'' | |
* \ .-\__ `-` ___/-. /
* ___`. .' /--.--\ `. . __
* ."" '< `.___\_<|>_/___.' >'"".
* | | : `- \`.;`\ _ /`;.`/ - ` : | |
* \ \ `-. \_ __\ /__ _/ .-` / /
* ======`-.____`-.___\_____/___.-`____.-'======
springframework和springboot
* `=---='
*          .............................................
*          佛⽈:bug泛滥,我已瘫痪!
*/
springboot使⽤logback会遇到的坑
Caused by: java.lang.IllegalArgumentException: LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Either remove Logback or the competing implementation (class org.apache.logging.slf4j.Log4jLoggerFactory loaded from file:/C:/Us  at org.springframework.util.Assert.instanceCheckFailed(Assert.java:389)
at org.springframework.util.Assert.isInstanceOf(Assert.java:327)
at org.springframework.boot.logging.LoggerContext(LogbackLoggingSystem.java:274)
at org.springframework.boot.logging.logback.LogbackLoggingSystem.beforeInitialize(LogbackLoggingSystem.java:98)
at org.springframework.boot.ApplicationStartingEvent(LoggingApplicationListener.java:230)
at org.springframework.boot.ApplicationEvent(LoggingApplicationListener.java:209)
at t.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
at t.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
at t.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
at t.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:122)
at org.t.event.EventPublishingRunListener.starting(EventPublishingRunListener.java:69)
at org.springframework.boot.SpringApplicationRunListeners.starting(SpringApplicationRunListeners.java:48)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:292)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107)
at com.light.SpringbootApplication.main(SpringbootApplication.java:32)
... 5 more
在spring boot中导⼊logback jar包会与spring-boot-starter-web冲突,应该是springboot中已经包含了这个包,
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
去掉这个导⼊就好了!
以上为个⼈经验,希望能给⼤家⼀个参考,也希望⼤家多多⽀持。

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。