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

Native Image Support #842

Open
driverpt opened this issue Aug 17, 2022 · 2 comments · May be fixed by #901
Open

Native Image Support #842

driverpt opened this issue Aug 17, 2022 · 2 comments · May be fixed by #901

Comments

@driverpt
Copy link

Is your feature request related to a problem? Please describe.
Currently we are trying to add this library to a Micronaut GraalVM Application and we're getting errors like:

org.graalvm.compiler.debug.GraalError: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: No instances of net.logstash.logback.pattern.AbstractJsonPatternParser$LayoutValueGetter are allowed in the image heap as this class should be initialized at image runtime. To see how this object got instantiated use --trace-object-instantiation=net.logstash.logback.pattern.AbstractJsonPatternParser$LayoutValueGetter.

This happens for all Static Classes

Describe the solution you'd like
Is there any way of adding a native-image.properties to make GraalVM Image possible?

Describe alternatives you've considered
Creating a custom serializer

Additional context
Micronaut 3.6.0 with AOT + GraalVM

@brenuart
Copy link
Collaborator

Hi Luis,

Your are not the first to report issues using the project with GraalVM. Unfortunately I have no experience at all with GraalVM and I'm a bit puzzled about where to start looking at... I found a quick "howto" on the net and used it to build a sample application hoping I could reproduce your problem. Unfortunately I could not reproduce your problem: I could build and execute my sample app without any problem.

Here is what I tried:

  • I wrote a small application with a single "main" that logs a couple of lines
  • build it using the org.graalvm.buildtools:native-maven-plugin (version 0.9.13) and the following configuration:
<plugin>
	<groupId>org.graalvm.buildtools</groupId>
	<artifactId>native-maven-plugin</artifactId>
	<version>0.9.13</version>
	<extensions>true</extensions>
	<executions>
		<execution>
			<id>build-native</id>
			<goals>
				<goal>build</goal>
			</goals>
			<phase>package</phase>
		</execution>
	</executions>
	<configuration>
		<mainClass>${mainClass}</mainClass>
		<buildArgs>
			<arg>--allow-incomplete-classpath</arg>
			<arg>--initialize-at-build-time</arg>
			<arg>-H:IncludeResources=.*\.xml$</arg>
		</buildArgs>
	</configuration>
</plugin>

Your error message refers to the AbstractJsonPatternParser so I configured logback to make use of the "pattern" JsonProvider. Here is the encoder I used:

<encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
    <providers>
        <timestamp/>
        <pattern>
            <pattern>{ "level": "%level", "message": "%message" }</pattern>
        </pattern>
    </providers>
</encoder>

I compiled the application with mvn package and got a working executable in the target folder. I could launch the app without problem and got my logs printed on the console in JSON format as expected.

Since I could not reproduce the problem myself, it would be nice if you could provide one yourself. Also don't hesitate to give me some more insight if you have some ideas about where the problem is and what could be a solution. Thx.

@brenuart brenuart added the status/waiting-for-feedback Waiting for feedback from the original author. Issue will be closed if feedback is not received soon label Aug 17, 2022
@driverpt
Copy link
Author

driverpt commented Aug 18, 2022

I will try that. In the meanwhile to reproduce the issue you can just use this pre-configured Micronaut app and add the Encoder (you must add the dependency)

cc @msailes @sdelamo

@github-actions github-actions bot removed the status/waiting-for-feedback Waiting for feedback from the original author. Issue will be closed if feedback is not received soon label Aug 18, 2022
driverpt added a commit to driverpt/logstash-logback-encoder that referenced this issue Nov 15, 2022
@philsttr philsttr linked a pull request Jun 17, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants