Last active
October 10, 2024 10:00
-
-
Save begrossi/d807280f54d3378d407e9c9a95e5d905 to your computer and use it in GitHub Desktop.
Revisions
-
begrossi revised this gist
Feb 9, 2021 . 1 changed file with 1 addition and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,7 @@ /** * RollingFileAppender with Lazy Initialization on GraalVM native image. */ public class LazyInitRollingFileAppender<E> extends ch.qos.logback.core.rolling.RollingFileAppender<E> { private boolean started = false; @Override -
begrossi revised this gist
Feb 9, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -39,7 +39,7 @@ public void doAppend(E eventObject) { } //THE BELOW CODE CAN BE SUBSTITUTED BY ImageInfo.inImageBuildtimeCode() if you have it on your classpath private static final String PROPERTY_IMAGE_CODE_VALUE_BUILDTIME = "buildtime"; private static final String PROPERTY_IMAGE_CODE_KEY = "org.graalvm.nativeimage.imagecode"; -
begrossi created this gist
Feb 9, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,56 @@ import ch.qos.logback.core.rolling.RollingFileAppender; /** * RollingFileAppender with Lazy Initialization on GraalVM native image. */ public class LazyInitRollingFileAppender<E> extends RollingFileAppender<E> { private boolean started = false; @Override public void start() { if (!inGraalImageBuildtimeCode()) { super.start(); this.started = true; } } /** * This method is synchronized to avoid double start from doAppender(). */ protected void maybeStart() { lock.lock(); try { if (!started) this.start(); } finally { lock.unlock(); } } @Override public void doAppend(E eventObject) { if (!inGraalImageBuildtimeCode()) { if (!started) maybeStart(); super.doAppend(eventObject); } } //THE ABOVE CODE CAN BE SUBSTITUTED BY ImageInfo.inImageBuildtimeCode() if you have it on your classpath private static final String PROPERTY_IMAGE_CODE_VALUE_BUILDTIME = "buildtime"; private static final String PROPERTY_IMAGE_CODE_KEY = "org.graalvm.nativeimage.imagecode"; /** * Returns true if (at the time of the call) code is executing in the context of Graal native image building * (e.g. in a static initializer of class that will be contained in the image). * Copy of graal code in org.graalvm.nativeimage.ImageInfo.inImageBuildtimeCode(). * https://github.com/oracle/graal/blob/master/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/ImageInfo.java */ private static boolean inGraalImageBuildtimeCode() { return PROPERTY_IMAGE_CODE_VALUE_BUILDTIME.equals(System.getProperty(PROPERTY_IMAGE_CODE_KEY)); } }