GithubHelp home page GithubHelp logo

Comments (2)

wilkinsona avatar wilkinsona commented on April 28, 2024

My suspicion when discussing this will @OlgaMaciaszek and @sdeleuze was that this would be due to our deferred logging but that doesn't appear to be the case.

As far as I can tell, the problem is that the failure is occurring before we've had a chance to initialize Logback and Logback in its default configuration doesn't work in a native image. This means that this error logging is silent:

Via some primitive debugging (adding System.out calls to a copy of SpringApplication) I've confirmed that this is an instance of org.apache.commons.logging.LogAdapter$Slf4jLocationAwareLog as we would expect and that error logging is enabled.

Further primitive debugging has shown that the problem is that Logback has no appenders configured. Things are in this state as Logback cannot load its various built-in configurator classes:

  • ch.qos.logback.classic.joran.SerializedModelConfigurator
  • ch.qos.logback.classic.util.DefaultJoranConfigurator
  • ch.qos.logback.classic.BasicConfigurator

When running on the JVM, BasicConfigurator creates a ConsoleAppender to which the error is logged. In a native image, BasicConfigurator cannot be loaded so Logback's left without any appenders and the event is silently dropped.

from spring-boot.

wilkinsona avatar wilkinsona commented on April 28, 2024

None of the three configurator classes could be loaded because NBT 0.9.8 uses a version of the Logback reachability metadata that does not allow them to be loaded reflectively. NBT 0.10.1 fixes this for two of the three configurators by using a more up-to-date version of the metadata by default. The metadata is missing reflection configuration for ch.qos.logback.classic.BasicConfigurator so it doesn't completely address the problem. This will have to be fixed in the reachability metadata and oracle/graalvm-reachability-metadata#454 is tracking that.

In the meantime, the problem can be worked around by using NBT 0.10.1 and an additional runtime hint:

package com.example;

import org.springframework.aot.hint.MemberCategory;
import org.springframework.aot.hint.RuntimeHints;
import org.springframework.aot.hint.RuntimeHintsRegistrar;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ImportRuntimeHints;

import com.example.NativeImageLoggingApplication.AdditionalLogbackHints;

import ch.qos.logback.classic.BasicConfigurator;

@SpringBootApplication
@ImportRuntimeHints(AdditionalLogbackHints.class)
public class NativeImageLoggingApplication {

	public static void main(String[] args) {
		SpringApplication.run(NativeImageLoggingApplication.class, args);
	}
	
	static class AdditionalLogbackHints implements RuntimeHintsRegistrar {

		@Override
		public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
			hints.reflection().registerType(BasicConfigurator.class, MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS);
		}
		
	}

}

from spring-boot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.