Spring Boot 有一个特性,它可以自动检测任何可用的日志框架(基于 org.springframework.boot.logging.LoggingSystem.SYSTEMS 中列出的类的存在 - Logback、Log4j 或 JUL)并从应用程序提供的日志配置文件或 Spring Boot 自己的默认配置文件配置它,与 Spring Boot 本身一起打包。

在将 Grails 3 应用程序作为 war 文件部署到 JBoss EAP 6(又名 WildFly 7)时,这会导致问题。 应用程序初始化时,Spring Boot 找到了 JBoss 提供的 JUL ( org.jboss.logmanager.LogManager ) 的日志实现,并在其上调用了 readConfiguration() 方法,导致日志配置困惑

  • 我想继续使用 JBoss 提供的日志记录实现和 JBoss 提供的日志记录配置,而不是在我的 war 文件中打包一个单独的日志记录实现。这允许我从服务器的配置文件中配置我在应用服务器上的所有应用程序。

  • 有没有办法禁用 Spring Boot 的日志自动配置? (我对 Spring Boot 检测和使用日志框架没问题;我只是不希望它尝试配置它。)我查看了源代码,但没有看到任何钩子(Hook)来控制它。

    相关源码:
  • LoggingApplicationListener
  • LoggingSystem
  • JavaLoggingSystem

  • 可能的想法:
  • 在收到 LoggingApplicationListenerApplicationStartedEvent 事件(触发日志配置)之前,以某种方式从应用程序监听器列表中删除 ApplicationEnvironmentPreparedEvent

  • 这些其他相关问题不能解决我的问题,因为用例不同:
  • Disable automatic logging configuration in spring boot
  • Spring boot and JBoss 8 Wildfly log configuration application
  • Spring-boot application configuration
  • Spring-Boot Logging configuration when deployed as .war

  • 版本:
  • Spring Boot - 1.3.3.RELEASE
  • Grails - 3.1.5
  • 最佳答案

    在 Spring Boot 1.3.x 中,您可以编写不执行任何操作的 org.springframework.boot.logging.LoggingSystem 自定义实现,然后将 org.springframework.boot.logging.LoggingSystem 系统属性设置为自定义实现的完全限定类名。

    我是 Spring Boot 1.4.x,不需要自定义实现,您只需将 org.springframework.boot.logging.LoggingSystem 系统属性设置为 none 即可。

    关于spring-boot - 如何在 Spring Boot 中禁用日志记录的自动配置?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39238685/

    10-16 21:31