4

Spring Boot has a feature where it automatically detects any logging framework available (based on the presence of classes listed in org.springframework.boot.logging.LoggingSystem.SYSTEMS - either Logback, Log4j or JUL) and configures it from either an application-provided logging config file or Spring Boot's own default config file, packaged withing Spring Boot itself.

This is causing problems when deploying a Grails 3 app as a war file to JBoss EAP 6 (a.k.a. WildFly 7). When the application initializes, Spring Boot finds the JBoss-provided logging implementation of JUL (org.jboss.logmanager.LogManager), and calls the readConfiguration() method on it, which messes up the logging configuration.

  • I would like to continue using the JBoss-provided logging implementation and JBoss-provided logging configuration, rather than packaging a separate logging implementation inside my war file. This allows me to configure all my applications on the app server from within the server's configuration file.

Is there any way to disable Spring Boot's auto-configuration of logging? (I'm okay with Spring Boot detecting and using the logging framework; I just don't want it to try to configure it.) I have looked at the source code, but don't see any hooks to control this.

Relevant source code:

Possible ideas:

  • Somehow remove LoggingApplicationListener from the list of application listeners before it receives the ApplicationStartedEvent or ApplicationEnvironmentPreparedEvent events (which triggers the configuration of logging)?

These other related questions don't solve my problem, since the use case is different:

Versions:

  • Spring Boot - 1.3.3.RELEASE
  • Grails - 3.1.5
Community
  • 1
  • 1
GreenGiant
  • 4,930
  • 1
  • 46
  • 76

2 Answers2

5

In Spring Boot 1.3.x you can write a custom implementation of org.springframework.boot.logging.LoggingSystem that doesn't do anything and then set the org.springframework.boot.logging.LoggingSystem system property to the fully-qualified class name of your custom implementation.

I'm Spring Boot 1.4.x, there's no need for the custom implementation and you can simply set the org.springframework.boot.logging.LoggingSystem system property to none instead.

Andy Wilkinson
  • 108,729
  • 24
  • 257
  • 242
  • If I use this route, will Spring Boot cease to log anything? Or will it write to stdout? – GreenGiant Aug 31 '16 at 17:16
  • 1
    It'll continue to log via calls to Commons Logging. As long as your app server supports Commons Logging or uses something like SLF4J's Commons Logging replacement it'll log to wherever you want based on your app server's logging configuration. – Andy Wilkinson Aug 31 '16 at 18:50
  • How or where would I set this environment property? I am deploying to JBoss EAP 6 as a war, and I'd rather not set this as a global system property on the server, if possible. Is there a convenient way to set it within the application itself or in some property file? (this is a Grails 3 app) – GreenGiant Sep 01 '16 at 15:57
  • Unfortunately not. It has to be a system property. – Andy Wilkinson Sep 01 '16 at 16:14
  • 1
    Wow. I seems like this would be a common use case for those deploying applications to an app server. I'm surprised it can't be configured per-application more easily, especially considering spring boot is very easily customizable in so many other ways. – GreenGiant Sep 01 '16 at 19:00
  • Perhaps you could contribute an enhancement? – Andy Wilkinson Sep 01 '16 at 19:14
1

This is not an answer per say, but some cues, you tell me if it helps:

Did you see this ? How-To Configure Logging for Spring-Boot + JBOSS 7.1 Server


Also, a fix as been made in Spring Boot 1.4 (if it does fix it for you and you have the option to upgrade): Spring Boot Logging initialization

My understanding of the fix: it delays the logger initialization, allowing you to define the java.util.logging.manager programmatically:

System.setProperty("java.util.logging.manager", "org.apache.logging.log4j.jul.LogManager")
Community
  • 1
  • 1
alexbt
  • 16,415
  • 6
  • 78
  • 87