Skip to content
This repository was archived by the owner on Feb 23, 2023. It is now read-only.
This repository was archived by the owner on Feb 23, 2023. It is now read-only.

Add support for logback.xml configuration file #625

Not planned
@yschimke

Description

@yschimke
$ ./gradlew bootBuildImage
...
    [creator]     javax.xml.parsers.FactoryFinder was unintentionally initialized at build time. org.slf4j.impl.StaticLoggerBinder caused initialization of this class with the following trace:
    [creator]           at javax.xml.parsers.FactoryFinder.<clinit>(FactoryFinder.java:46)
    [creator]           at javax.xml.parsers.SAXParserFactory.newInstance(SAXParserFactory.java:147)
    [creator]           at ch.qos.logback.core.joran.event.SaxEventRecorder.buildSaxParser(SaxEventRecorder.java:79)
    [creator]           at ch.qos.logback.core.joran.event.SaxEventRecorder.recordEvents(SaxEventRecorder.java:57)
    [creator]           at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:151)
    [creator]           at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:110)
    [creator]           at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:53)
    [creator]           at ch.qos.logback.classic.util.ContextInitializer.configureByResource(ContextInitializer.java:75)
    [creator]           at ch.qos.logback.classic.util.ContextInitializer.autoConfig(ContextInitializer.java:150)
    [creator]           at org.slf4j.impl.StaticLoggerBinder.init(StaticLoggerBinder.java:84)
    [creator]           at org.slf4j.impl.StaticLoggerBinder.<clinit>(StaticLoggerBinder.java:55)

Activity

yschimke

yschimke commented on Mar 17, 2021

@yschimke
Author

I'm testing now without this but I believe the codepath is when it hit src/main/resources/logback.xml

added this to the 0.9.1 milestone on Mar 17, 2021
self-assigned this
on Mar 17, 2021
sdeleuze

sdeleuze commented on Mar 17, 2021

@sdeleuze
Contributor

Not an easy one:

Error: Classes that should be initialized at run time got initialized during image building:
 javax.xml.parsers.FactoryFinder was unintentionally initialized at build time. org.slf4j.impl.StaticLoggerBinder caused initialization of this class with the following trace: 
	at javax.xml.parsers.FactoryFinder.<clinit>(FactoryFinder.java:45)
	at javax.xml.parsers.SAXParserFactory.newInstance(SAXParserFactory.java:127)
	at ch.qos.logback.core.joran.event.SaxEventRecorder.buildSaxParser(SaxEventRecorder.java:79)
	at ch.qos.logback.core.joran.event.SaxEventRecorder.recordEvents(SaxEventRecorder.java:57)
	at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:151)
	at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:110)
	at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:53)
	at ch.qos.logback.classic.util.ContextInitializer.configureByResource(ContextInitializer.java:75)
	at ch.qos.logback.classic.util.ContextInitializer.autoConfig(ContextInitializer.java:150)
	at org.slf4j.impl.StaticLoggerBinder.init(StaticLoggerBinder.java:84)
	at org.slf4j.impl.StaticLoggerBinder.<clinit>(StaticLoggerBinder.java:55)

We do our best to limit build time initialization but with SLF4J that's hard to avoid and here SLF4J build time init trigger logback SaxEventRecorder which performs javax.xml.parsers.FactoryFinder static init at build time.

Trying to intialize javax.xml.parsers.FactoryFinder at build time requires to configure a lot of other classes initialized at build time too so that seems a dead end to me.

Any thoughts @aclement?

yschimke

yschimke commented on Mar 17, 2021

@yschimke
Author

It worked for me just by deleting the file (I got further), so I'm not blocked.

sdeleuze

sdeleuze commented on Mar 17, 2021

@sdeleuze
Contributor

I move this issue to 0.10 since solving that will require deeper changes.

modified the milestones: 0.9.1, 0.10.0 on Mar 17, 2021
cipley

cipley commented on Mar 19, 2021

@cipley

Hi,

I stumble upon this issue as well, and want to add some points;
It seems like having the logback file logback-spring.xml will result in below error:

Logging system failed to initialize using configuration from 'null'
java.lang.IllegalStateException: Could not initialize Logback logging from classpath:logback-spring.xml
        at org.springframework.boot.logging.logback.LogbackLoggingSystem.loadConfiguration(LogbackLoggingSystem.java:168)
        at org.springframework.boot.logging.AbstractLoggingSystem.initializeWithConventions(AbstractLoggingSystem.java:80)
        at org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:60)
        at org.springframework.boot.logging.logback.LogbackLoggingSystem.initialize(LogbackLoggingSystem.java:132)
        at org.springframework.boot.context.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:312)
        at org.springframework.boot.context.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:281)
        at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:239)
        at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:216)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:203)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:196)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:170)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:148)
        at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:82)
        at org.springframework.boot.SpringApplicationRunListeners.lambda$environmentPrepared$2(SpringApplicationRunListeners.java:63)
        at java.util.ArrayList.forEach(ArrayList.java:1259)
        at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:117)
        at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:111)
        at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:62)
        at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:362)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:320)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1311)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1300)
        at i.c.t.d.b.n.api.Application.main(Application.java:18)
Caused by: ch.qos.logback.core.LogbackException: Unexpected filename extension of file [resource:logback-spring.xml]. Should be either .groovy or .xml
        at ch.qos.logback.classic.util.ContextInitializer.configureByResource(ContextInitializer.java:58)
        at org.springframework.boot.logging.logback.LogbackLoggingSystem.configureByResourceUrl(LogbackLoggingSystem.java:191)
        at org.springframework.boot.logging.logback.LogbackLoggingSystem.loadConfiguration(LogbackLoggingSystem.java:165)
        ... 22 more

Which is quite odd since the logback file is actually have the correct extensions.

While in my case, when using logback.xml logback file, it will result in build error (I'm using maven btw);

...
[INFO]     [creator]     Error: Classes that should be initialized at run time got initialized during image building:
[INFO]     [creator]      org.springframework.boot.ansi.AnsiOutput was unintentionally initialized at build time. To see why org.springframework.boot.ansi.AnsiOutput got initialized use --trace-class-initialization=org.springframework.boot.ansi.AnsiOutput
[INFO]     [creator]     org.springframework.boot.logging.logback.ColorConverter was unintentionally initialized at build time. To see why org.springframework.boot.logging.logback.ColorConverter got initialized use --trace-class-initialization=org.springframework.boot.logging.logback.ColorConverter
[INFO]     [creator]
[INFO]     [creator]     Error: Use -H:+ReportExceptionStackTraces to print stacktrace of underlying exception
[INFO]     [creator]     Error: Image build request failed with exit status 1
[INFO]     [creator]     unable to invoke layer creator
[INFO]     [creator]     unable to contribute native-image layer
[INFO]     [creator]     error running build
[INFO]     [creator]     exit status 1
[INFO]     [creator]     ERROR: failed to build: exit status 1
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  02:51 min
[INFO] Finished at: 2021-03-19T05:32:17+07:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.4.3:build-image (default-cli) on project networkprofile-bs-api: Execution default-cli of goal org.springframework.boot:spring-boot-maven-plugin:2.4.3:build-image failed: Builder lifecycle 'creator' failed with status code 145 -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException

and yes, deleting the logback file causes the issue to disappear.

changed the title [-]logback config file seems to fail the build[/-] [+]Add support for logback.xml configuration file[/+] on Mar 19, 2021
sdeleuze

sdeleuze commented on Mar 19, 2021

@sdeleuze
Contributor

This temporary limitation is now documented.

When we fix that, let's make sure <springProperty /> is supported as described in #607.

removed this from the 0.10.0 milestone on Mar 22, 2021

42 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    for: external-projectFor an external project and not something we can fixtype: compatibilityNative image compatibility issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @bclozel@sdeleuze@yschimke@celcius112@chenzhiguo

        Issue actions

          Add support for logback.xml configuration file · Issue #625 · spring-attic/spring-native