Skip to content

[native-image] Logback RollingFileAppender does not compile in native image #1323

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

Closed
hhandoko opened this issue May 23, 2019 · 8 comments · Fixed by hhandoko/scala-http4s-realworld-example-app#32
Assignees

Comments

@hhandoko
Copy link

This is a similar issue to #807 .

Logback works fine with ConsoleAppender, no special native-image configuration needed. I've been having problems trying to setup logback's RollingFileAppender. Adding this class to runtime initialization resulted in a the following error:

Error: No instances are allowed in the image heap for a class that is initialized or reinitialized at image runtime: ch.qos.logback.core.rolling.RollingFileAppender. Try marking this class for build-time initialization with --initialize-at-build-time=ch.qos.logback.core.rolling.RollingFileAppender

However, adding this class at build-time initialization also throws an error, as below:

Warning: Aborting stand-alone image build. Detected a FileDescriptor in the image heap. File descriptors opened during image generation are no longer open at image run time, and the files might not even be present anymore at image run time. The object was probably created by a class initializer and is reachable from a static field. By default, all class initialization is done during native image building.You can manually delay class initialization to image run time by using the option -H:ClassInitialization=<class-name>. Or you can write your own initialization methods and call them explicitly from your main entry point.

Note that I've added and configured logback reflection file as found in: https://github.com/sdeleuze/graal-issues/blob/master/logback/graal.json

@hhandoko
Copy link
Author

Repo branch to demonstrate the issue: https://github.com/hhandoko/scala-http4s-realworld-example-app/tree/chore/rolling_file_log_appender

Run ./scripts/graal/bin/setup.sh && ./scripts/graal/bin/dist.sh to replicate.

@cstancu cstancu self-assigned this May 23, 2019
@qdeee
Copy link
Contributor

qdeee commented May 28, 2019

I faced with the same problem when I tried to use native-image for my application. I don't know why runtime initialization failed in your case but build-time initialization failure is absolutely correct: logback opens FileOutputStream (and corresponding file descriptors in OS) on logging initializing and native-image forbids it because these file descriptors won't exist at runtime.
I managed to fix it by writting subclass for FileAppender that closes FileOutputStream after each append at build time and keeps file descriptors open at runtime (as usual).

@hhandoko
Copy link
Author

Thanks for the tips @qdeee , do you have this example in GitHub / open source repo by any chance?

@leonxandercs
Copy link

I faced with the same problem when I tried to use native-image for my application. I don't know why runtime initialization failed in your case but build-time initialization failure is absolutely correct: logback opens FileOutputStream (and corresponding file descriptors in OS) on logging initializing and native-image forbids it because these file descriptors won't exist at runtime.
I managed to fix it by writting subclass for FileAppender that closes FileOutputStream after each append at build time and keeps file descriptors open at runtime (as usual).

Could you share your solution please?

@begrossi
Copy link

begrossi commented Feb 4, 2021

Guys, any update on this issue?

@hhandoko
Copy link
Author

hhandoko commented Mar 6, 2021

Your solution works for me @begrossi ! Thanks 👍

My code (Scala) with the working solution can be seen on the PR link above.

@hhandoko hhandoko closed this as completed Mar 6, 2021
@brianwyka
Copy link

@hhandoko, can you reopen this since its just a workaround?

@mvillafuertem
Copy link

Hi there,

I'm getting the error below while compiling into native-image:


[error] Error: Classes that should be initialized at run time got initialized during image building:
[error]  ch.qos.logback.classic.Logger the class was requested to be initialized at run time (from the command line). To see why ch.qos.logback.classic.Logger got initialized use --trace-class-initialization=ch.qos.logback.classic.Logger
[error] ch.qos.logback.classic.Level the class was requested to be initialized at run time (from the command line). To see why ch.qos.logback.classic.Level got initialized use --trace-class-initialization=ch.qos.logback.classic.Level
[error] com.oracle.svm.core.util.UserError$UserException: Classes that should be initialized at run time got initialized during image building:
[error]  ch.qos.logback.classic.Logger the class was requested to be initialized at run time (from the command line). To see why ch.qos.logback.classic.Logger got initialized use --trace-class-initialization=ch.qos.logback.classic.Logger
[error] ch.qos.logback.classic.Level the class was requested to be initialized at run time (from the command line). To see why ch.qos.logback.classic.Level got initialized use --trace-class-initialization=ch.qos.logback.classic.Level
[error]         at com.oracle.svm.core.util.UserError.abort(UserError.java:68)
[error]         at com.oracle.svm.hosted.classinitialization.ConfigurableClassInitialization.checkDelayedInitialization(ConfigurableClassInitialization.java:545)
[error]         at com.oracle.svm.hosted.classinitialization.ClassInitializationFeature.duringAnalysis(ClassInitializationFeature.java:228)
[error]         at com.oracle.svm.hosted.NativeImageGenerator.lambda$runPointsToAnalysis$14(NativeImageGenerator.java:765)
[error]         at com.oracle.svm.hosted.FeatureHandler.forEachFeature(FeatureHandler.java:71)
[error]         at com.oracle.svm.hosted.NativeImageGenerator.runPointsToAnalysis(NativeImageGenerator.java:765)
[error]         at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:582)
[error]         at com.oracle.svm.hosted.NativeImageGenerator.lambda$run$2(NativeImageGenerator.java:495)
[error]         at java.base/java.util.concurrent.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1407)
[error]         at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
[error]         at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
[error]         at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
[error]         at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
[error]         at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)

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.

7 participants