This repository was archived by the owner on Apr 23, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 7 files changed +438
-1
lines changed
src/main/java/ch/qos/logback/ext/graalvm/appenders Expand file tree Collapse file tree 7 files changed +438
-1
lines changed Original file line number Diff line number Diff line change 1+
2+ description = POM_DESCRIPTION
3+ dependencies {
4+ compileOnly ' ch.qos.logback:logback-classic:1.2.3'
5+ compileOnly ' org.graalvm.sdk:graal-sdk:22.3.0'
6+ }
Original file line number Diff line number Diff line change 1+ POM_NAME =logback-ext-graalvm
2+ POM_ARTIFACT_ID =logback-ext-graalvm
3+ POM_PACKAGING =jar
4+ POM_DESCRIPTION =" Logback Extensions :: GraalVM"
Original file line number Diff line number Diff line change 1+ package ch .qos .logback .ext .graalvm .appenders ;
2+
3+ import org .graalvm .nativeimage .ImageInfo ;
4+
5+ import ch .qos .logback .classic .spi .ILoggingEvent ;
6+
7+ /**
8+ * Async appender for using with GraalVM.
9+ */
10+ public class GraalVMLazyAsyncAppender extends LazyAsyncAppender {
11+
12+ /**
13+ * In the build phase of the image appender should not be started.
14+ */
15+ @ Override
16+ public void start () {
17+ if (!ImageInfo .inImageBuildtimeCode ()) {
18+ super .start ();
19+ }
20+ }
21+
22+ /**
23+ * While getting the even in NOT build image phase async appender must be started - otherwise start it.
24+ *
25+ * @param eventObject event to append.
26+ */
27+ @ Override
28+ public void doAppend (ILoggingEvent eventObject ) {
29+ if (!ImageInfo .inImageBuildtimeCode ()) {
30+ if (!isStarted ()) {
31+ synchronized (this ) {
32+ if (!isStarted ()) {
33+ super .start ();
34+ }
35+ }
36+ }
37+ super .doAppend (eventObject );
38+ }
39+ }
40+ }
Original file line number Diff line number Diff line change 1+ package ch .qos .logback .ext .graalvm .appenders ;
2+
3+ import org .graalvm .nativeimage .ImageInfo ;
4+
5+ import ch .qos .logback .core .rolling .RollingFileAppender ;
6+
7+ /**
8+ * GraalVM implementation of the {@link RollingFileAppender} with initialization of all files descriptors not in the build image phase.
9+ */
10+ public class GraalVMRollingFileAppender <E > extends RollingFileAppender <E > {
11+
12+ /**
13+ * In the build phase of the image appender should not be started.
14+ */
15+ @ Override
16+ public void start () {
17+ if (!ImageInfo .inImageBuildtimeCode ()) {
18+ super .start ();
19+ }
20+ }
21+
22+ /**
23+ * While getting the even in NOT build image phase async appender must be started - otherwise start it.
24+ *
25+ * @param eventObject event to append.
26+ */
27+ @ Override
28+ public void doAppend (E eventObject ) {
29+ if (!ImageInfo .inImageBuildtimeCode ()) {
30+ if (!isStarted ()) {
31+ synchronized (this ) {
32+ if (!isStarted ()) {
33+ super .start ();
34+ }
35+ }
36+ }
37+ super .doAppend (eventObject );
38+ }
39+ }
40+ }
Original file line number Diff line number Diff line change 1+ package ch .qos .logback .ext .graalvm .appenders ;
2+
3+ import ch .qos .logback .classic .Level ;
4+ import ch .qos .logback .classic .spi .ILoggingEvent ;
5+
6+ /**
7+ * Lazy async appender with worker initialization on start phase.
8+ */
9+ public class LazyAsyncAppender extends LazyAsyncAppenderBase <ILoggingEvent > {
10+
11+ boolean includeCallerData = false ;
12+
13+ /**
14+ * Events of level TRACE, DEBUG and INFO are deemed to be discardable.
15+ *
16+ * @param event
17+ * @return true if the event is of level TRACE, DEBUG or INFO false otherwise.
18+ */
19+ protected boolean isDiscardable (ILoggingEvent event ) {
20+ Level level = event .getLevel ();
21+ return level .toInt () <= Level .INFO_INT ;
22+ }
23+
24+ protected void preprocess (ILoggingEvent eventObject ) {
25+ eventObject .prepareForDeferredProcessing ();
26+ if (includeCallerData )
27+ eventObject .getCallerData ();
28+ }
29+
30+ public boolean isIncludeCallerData () {
31+ return includeCallerData ;
32+ }
33+
34+ public void setIncludeCallerData (boolean includeCallerData ) {
35+ this .includeCallerData = includeCallerData ;
36+ }
37+
38+ }
You can’t perform that action at this time.
0 commit comments