Skip to content
This repository was archived by the owner on Apr 23, 2024. It is now read-only.

Commit 93b22d7

Browse files
Adding new module with supporting graalvm appenders. Signed-off-by: Dmitry Kubakhov <[email protected]>
Signed-off-by: DmitryKubakhov <[email protected]>
1 parent 2d7dea7 commit 93b22d7

File tree

7 files changed

+438
-1
lines changed

7 files changed

+438
-1
lines changed

graalvm/build.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
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+
}

graalvm/gradle.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
POM_NAME=logback-ext-graalvm
2+
POM_ARTIFACT_ID=logback-ext-graalvm
3+
POM_PACKAGING=jar
4+
POM_DESCRIPTION="Logback Extensions :: GraalVM"
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
}

0 commit comments

Comments
 (0)