springboot 使用logback启动报警报错的解决

网友投稿 1430 2022-12-24

springboot 使用logback启动报警报错的解决

springboot 使用logback启动报警报错的解决

springboot logback启动报警报错

报错信息如下:

16:06:07,484 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml]

16:06:07,484 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy]

16:06:07,4BgGAlLm85 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback.xml] at [file:/C:/Users/Administrator/Desktop/***/***/target/classes/logback.xml]

16:06:07,638 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - debug attribute not set

16:06:07,646 |-INFO in ch.qos.logback.core.joran.action.APPenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]

16:06:07,653 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [consoleAppender]

先说解决方法

把日志文件名称改为-spring结尾就不报警了!!! logback-spring.xml

tips(springboot日志使用logback):

Spring Boot官方推荐优先使用带有-spring的文件名作为你的日志配置(如使用logback-spring.xml,而不是logback.xml),如果想自定义文件名,可以通过logging.config属性指定自定义的名字:

logging.config=classpath:my-logging-config.xml

官方start包中已经默认集成了slf4j和logback不用导入任何日志依赖

推荐使用logback,性能优于log4j

设置logback彩色日志

${log.consolePattern}

utf8

springboot多环境开发日志

banner.txt

/***

* _ooOoo_

* o8888888o

* 88" . "88

* (| -_- |)

* O\ = /O

* ___/`---'\____

* . ' \\| |// `.

* / \\||| : |||// \

* / _||||| -:- |||||- \

* | | \\\ - /// | |

* | \_| ''\---/'' | |

* \ .-\__ `-` ___/-. /

* ___`. .' /--.--\ `. . __

* ."" '< `.___\_<|>_/___.' >'"".

* | | : `- \`.;`\ _ /`;.`/ - ` : | |

* \ \ `-. \_ __\ /__ _/ .-` / /

* ======`-.____`-.___\_____/___.-`____.-'======

* `=---='

* .............................................

* 佛曰: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:/Users/fyk/.m2/repository/org/apache/logging/log4j/log4j-slf4j-impl/2.7/log4j-slf4j-impl-2.7.jar). If you are using WebLogic you will need to add 'org.slf4j' to prefer-application-packages in WEB-INF/weblogic.xml: org.apache.logging.slf4j.Log4jLoggerFactory

at org.springframework.util.Assert.instanceCheckFailed(Assert.java:389)

at org.springframework.util.Asserhttp://t.isInstanceOf(Assert.java:327)

at org.springframework.boot.logging.logback.LogbackLoggingSystem.getLoggerContext(LogbackLoggingSystem.java:274)

at org.springframework.boot.logging.logback.LogbackLoggingSystem.beforeInitialize(LogbackLoggingSystem.java:98)

at org.springframework.boot.logging.LoggingApplicationListener.onApplicationStartingEvent(LoggingApplicationListener.java:230)

at org.springframework.boot.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:209)

at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)

at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)

at org.springframework.context.event.SimpleApplicatiohttp://nEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)

at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:122)

at org.springframework.boot.context.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中已经包含了这个包,

ch.qos.logback

logback-classic

1.2.3

去掉这个导入就好了!

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:智能车载终端属于前装吗(智能车载终端是干嘛的)
下一篇:小程序app区别(小程序与app的区别)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~