Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add native-image support for JavaLoggingSystem #31531

Closed
mhalbritter opened this issue Jun 27, 2022 · 4 comments
Closed

Add native-image support for JavaLoggingSystem #31531

mhalbritter opened this issue Jun 27, 2022 · 4 comments
Assignees
Labels
theme: aot An issue related to Ahead-of-time processing type: enhancement A general enhancement
Milestone

Comments

@mhalbritter
Copy link
Contributor

The spring-native sample cloud-function-netty has this in the POM:

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-webflux</artifactId>
			<exclusions>
				<exclusion>
					<groupId>org.springframework.boot</groupId>
					<artifactId>spring-boot-starter-logging</artifactId>
				</exclusion>
			</exclusions>
		</dependency>

When running with mvn spring-boot:run, it starts up (and even logs something).

When I compile it to a native-image, i get this error:

Exception in thread "main" java.lang.IllegalStateException: No suitable logging system located
        at org.springframework.util.Assert.state(Assert.java:76)
        at org.springframework.boot.logging.LoggingSystem.get(LoggingSystem.java:160)
        at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationStartingEvent(LoggingApplicationListener.java:231)
        at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:213)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:131)
        at org.springframework.boot.context.event.EventPublishingRunListener.starting(EventPublishingRunListener.java:79)
        at org.springframework.boot.SpringApplicationRunListeners.lambda$starting$0(SpringApplicationRunListeners.java:56)
        at java.util.ArrayList.forEach(ArrayList.java:1511)
        at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:120)
        at org.springframework.boot.SpringApplicationRunListeners.starting(SpringApplicationRunListeners.java:56)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:301)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1301)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1290)
        at com.example.demo.DemoApplication.main(DemoApplication.java:13)

This can be fixed by removing the exclusion, I just wonder why it runs in JVM mode but not on a native-image.

Feel free to close if the use-case is somewhat strange and not supported (expect logging when excluding the logging-starter).

@mhalbritter mhalbritter added type: bug A general bug theme: aot An issue related to Ahead-of-time processing labels Jun 27, 2022
@mhalbritter mhalbritter added this to the 3.0.x milestone Jun 27, 2022
@wilkinsona
Copy link
Member

Without the logging starter, we'll fall back to using JavaLoggingSystem. There's a reflective check for the presence of java.util.logging.LogManager and I suspect we're missing a hint for it. I don't see why we wouldn't want to support this on native at some point. If it requires more than a hint for that class, it might be worth deferring it for now.

@wilkinsona wilkinsona changed the title native-image: No suitable logging system located only in native image No suitable logging system located only in native image Jun 27, 2022
@wilkinsona wilkinsona changed the title No suitable logging system located only in native image When logging starter is excluded, native image fails to start with "No suitable logging system located" Jun 27, 2022
@mhalbritter mhalbritter changed the title When logging starter is excluded, native image fails to start with "No suitable logging system located" Add native-image support for JavaLoggingSystem Jun 28, 2022
@mhalbritter mhalbritter added type: enhancement A general enhancement and removed type: bug A general bug labels Jun 28, 2022
@sdeleuze
Copy link
Contributor

sdeleuze commented Jul 7, 2022

I suspect this exclusion is coming from a copy and paste from the commandlinerunner sample where we added this exclusion because this use case was broken initially so that makes sense to fix it IMO.

I have refined Spring Framework constant field handling via sdeleuze/spring-framework@5397d47 in order to recognize PRESENT fields like used in Spring Boot classes like org.springframework.boot.logging.logback.LogbackLoggingSystem.Factory#PRESENT.

With that change, I just had to add a resource hint for org/springframework/boot/logging/java/logging.properties to make it work. Could you please add that on Spring Boot side like you did for other resources in 1efa474 for example?

@mhalbritter mhalbritter self-assigned this Jul 7, 2022
@mhalbritter
Copy link
Contributor Author

Done. @sdeleuze can you please ping me when sdeleuze/spring-framework@5397d47 is in SF main?

@mhalbritter
Copy link
Contributor Author

Nvm, it's already in main. Sorry for the noise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme: aot An issue related to Ahead-of-time processing type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants