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,485 |-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彩色日志

<property name="log.consolePattern" value="%highlight(%date{yyyy-MM-dd HH:mm:ss.SSS}) %boldYellow([%thread]) %highlight([%-5level])  %boldCyan([%replace(%caller{1}){'\t|Caller.{1}0|\r\n', ''}]) %msg%n"/>

<!-- 控制台设置,主要是上方pattern修改就可以,其他地方可以用不同pattern -->
<appender name="CONSOLE_APPENDER" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
        <pattern>${log.consolePattern}</pattern>  <!-- 控制台日志输出格式 -->
        <charset>utf8</charset>
    </encoder>
</appender>

springboot多环境开发日志

<!-- 测试环境+开发环境. 多个使用逗号隔开 -->
<springProfile name="test,dev">
 <logger name="工程包路径" level="info" />
</springProfile>
<!-- 生产环境. -->
<springProfile name="prod">
 <logger name="工程包路径" level="ERROR" />
</springProfile>

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.Assert.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.SimpleApplicationEventMulticaster.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中已经包含了这个包,

   <dependency>
   <groupId>ch.qos.logback</groupId>
   <artifactId>logback-classic</artifactId>
   <version>1.2.3</version>
  </dependency>

去掉这个导入就好了!

以上为个人经验,希望能给大家一个参考,也希望大家多多支持我们。

(0)

相关推荐

  • Springboot如何使用logback实现多环境配置?

    前言 Logback是由log4j创始人设计的又一个开源日记组件,Logback 当前分成三个模块:logback-core,logback- classic和logback-access.logback-core是其它两个模块的基础模块,logback-classic是log4j的一个改良版本.此外logback-classic完整实现SLF4J API使你可以很方便地更换成其它日记系统如log4j或JDK14 Logging.logback-access访问模块与Servlet容器集成提供通

  • springboot项目配置logback日志系统的实现

    记录springboot项目配置logback日志文件管理: logback依赖jar包 SpringBoot项目配置logback理论上需要添加logback-classic依赖jar包: <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> <version>1.2.3</version> <

  • SpringBoot配置logback.xml 多环境的操作步骤

    前提 logback日志文件要实现springboot多环境配置,不然每次都需要修改logback.xml里面的配置文件,所以很麻烦. 操作步骤 1.resource文件的内容结构如下: 2.配置application.yml spring: profiles: active: dev logging: config: classpath:logback-${spring.profiles.active}.xml 3.配置lockback-dev.xml 这个地方就可以实现自己的多环境日志配置了

  • springboot如何使用logback-spring配置日志格式,并分环境配置

    配置不生效的解决办法 注意:如果配置不生效,则说明spring优先加载了其他配置: 解决办法: 添加启动参数 -Dlogging.config=classpath:logback-spring.xml 修改名字为 logback.xml, SpringBoot首先去查找标准的日志配置文件,如果找不到在去找拼接Spring的配置的文件, 标准文件名: "logback-test.groovy", "logback-test.xml", "logback.gr

  • 详解Springboot之Logback的使用学习

    一.导入依赖 普通项目 <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-core</artifactId> <version>1.1.11</version> </dependency> <dependency> <groupId>ch.qos.logback</groupId> <a

  • 解决springboot使用logback日志出现LOG_PATH_IS_UNDEFINED文件夹的问题

    application.properties 加入以下配置 #logback home logging.path=D:/logs/esb-producer logback.xml <property name="LOG_PATH" value="${LOG_PATH:- }" /> <appender name="INFO_FILE" class="ch.qos.logback.core.rolling.Rolling

  • 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

  • 解决springboot整合cxf启动报错,原因是版本问题

    springboot整合cxf启动报错 错误信息如下 [DEBUG] 2021-01-26 11:28:47,848 [main] org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter - Application failed to start due to an exception org.springframework.beans.factory.NoSuchBeanDefinitionException: N

  • 文件上传SpringBoot后端MultipartFile参数报空问题的解决办法

    最近写了一个文件上传的小demo,就是简单的前端html页面,后端controller接收,但是后端一直报错文件为null,看了很多文章,有说spring-boot自带的org.springframework.web.multipart.MultipartFile和Multipart冲突了,要在启动类中加入@EnableAutoConfiguration(exclue={MultipartAutoConfiguration.class}),有说要在MultipartFile参数前加上@Reque

  • springBoot启动报错log4j冲突的解决方案

    springBoot启动报错log4j冲突 先上一段报错内容 SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/D:/soft/apache-tomcat-8.5.31/webapps/ui/WEB-INF/lib/log4j-slf4j-impl-2.7.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found

  • SpringBoot启动报错Failed to determine a suitable driver class

    SpringBoot启动报错如下 Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 2019-05-06 21:27:18.275 ERROR 10968 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** AP

  • Springboot项目因为kackson版本问题启动报错解决方案

    问题现象 org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat     at org.springframew

  • Tomcat启动springboot项目war包报错:启动子级时出错的问题

    今天公司springboot项目准备部署到测试服务器上进行测试,打包好war后放到tomcat里面启动后,前端文件能访问到,但是接口请求一直是404,一直找了很久的原因,tomcat启动是成功的,war打包的时候也提示build success了,tomcat启动日志发现报错: java.lang.IllegalStateException: 启动子级时出错   at org.apache.catalina.core.ContainerBase.addChildInternal(Containe

  • 解决SpringBoot webSocket 资源无法加载、tomcat启动报错的问题

    问题描述: 1. 项目集成WebSocket,且打包发布tomcat时出现websocket is already in CLOSING or CLOSE state这样的问题,建议参考"解决方法二",但是"解决方法一"请要了解查看 ,因为解决方法二是在一的基础上进行更正 2. 如果出现javax.websocket.server.ServerContainer not available这样的错误,请参考"解决方法一"中步骤3 解决方法一:(常

  • 解决springboot项目不配置数据源启动报错问题

    目录 springboot项目不配置数据源启动报错 springboot配置双数据源报错 springboot项目不配置数据源启动报错 spring boot默认会加载 org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration 在启动类上加上 @SpringBootApplication(exclude={DataSourceAutoConfiguration.class, HibernateJpaAutoCo

  • springboot集成springCloud中gateway时启动报错的解决

    在项目中引入springcloud中的gateway时报以下错误 Description: Parameter 0 of method modifyRequestBodyGatewayFilterFactory in org.springframework.cloud.gateway.config.GatewayAutoConfiguration required a bean of type 'org.springframework.http.codec.ServerCodecConfigur

随机推荐