Spring 应用程序启动之前的 Spring Boot 设置日志记录 [英] Spring boot setup logging before spring application starts

查看:36
本文介绍了Spring 应用程序启动之前的 Spring Boot 设置日志记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目,我需要在启动 SpringApplication 之前使用日志记录机制.我怎样才能做到这一点?

I have a project where I need the logging mechanism before I start the SpringApplication. How can I achieve that?

我尝试设置自己的日志记录机制 (LogManager.getLogManager().readConfiguration()),但它在 spring 应用程序启动时被覆盖.

I tried to setup my own logging mechanism (LogManager.getLogManager().readConfiguration()), but it is overridden when the spring application starts.

基本上我想在任何地方使用相同的日志记录机制.

Basically I want to use the same logging mechanism everywhere.

推荐答案

我设法通过从我的项目中删除spring-boot-starter-logging"依赖项并添加 'org.slf4j:slf4j-jdk14:1.7 来解决我的问题.5' 和 'commons-logging:commons-logging:1.1.1'.

I manage to solve my issue by removing "spring-boot-starter-logging" dependency from my project and adding 'org.slf4j:slf4j-jdk14:1.7.5' and 'commons-logging:commons-logging:1.1.1'.

我使用 gradle,所以在我的情况下,我是通过以下方式实现的:

I use gradle so in my case I achieve that by:

compile("org.springframework.boot:spring-boot-starter-web") {
    exclude module: "spring-boot-starter-logging"
}
compile("org.springframework.boot:spring-boot-starter-actuator") {
    exclude module: "spring-boot-starter-logging"
}

compile('org.slf4j:slf4j-jdk14:1.7.5')
compile('commons-logging:commons-logging:1.1.1')

删除 LoggingApplicationListener 和 logback.xml 不起作用.

Removing LoggingApplicationListener and logback.xml didn't worked.

这篇关于Spring 应用程序启动之前的 Spring Boot 设置日志记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆