Skip to content
This repository was archived by the owner on Apr 23, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions graalvm/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

description = POM_DESCRIPTION
dependencies {
compileOnly 'ch.qos.logback:logback-classic:1.2.3'
compileOnly 'org.graalvm.sdk:graal-sdk:22.3.0'
}
4 changes: 4 additions & 0 deletions graalvm/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
POM_NAME=logback-ext-graalvm
POM_ARTIFACT_ID=logback-ext-graalvm
POM_PACKAGING=jar
POM_DESCRIPTION="Logback Extensions :: GraalVM"
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package ch.qos.logback.ext.graalvm.appenders;

import org.graalvm.nativeimage.ImageInfo;

import ch.qos.logback.classic.spi.ILoggingEvent;

/**
* Async appender for using with GraalVM.
*/
public class GraalVMLazyAsyncAppender extends LazyAsyncAppender {

/**
* In the build phase of the image appender should not be started.
*/
@Override
public void start() {
if (!ImageInfo.inImageBuildtimeCode()) {
super.start();
}
}

/**
* While getting the even in NOT build image phase async appender must be started - otherwise start it.
*
* @param eventObject event to append.
*/
@Override
public void doAppend(ILoggingEvent eventObject) {
if (!ImageInfo.inImageBuildtimeCode()) {
if (!isStarted()) {
synchronized (this) {
if (!isStarted()) {
super.start();
}
}
}
super.doAppend(eventObject);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package ch.qos.logback.ext.graalvm.appenders;

import org.graalvm.nativeimage.ImageInfo;

import ch.qos.logback.core.rolling.RollingFileAppender;

/**
* GraalVM implementation of the {@link RollingFileAppender} with initialization of all files descriptors not in the build image phase.
*/
public class GraalVMRollingFileAppender<E> extends RollingFileAppender<E> {

/**
* In the build phase of the image appender should not be started.
*/
@Override
public void start() {
if (!ImageInfo.inImageBuildtimeCode()) {
super.start();
}
}

/**
* While getting the even in NOT build image phase async appender must be started - otherwise start it.
*
* @param eventObject event to append.
*/
@Override
public void doAppend(E eventObject) {
if (!ImageInfo.inImageBuildtimeCode()) {
if (!isStarted()) {
synchronized (this) {
if (!isStarted()) {
super.start();
}
}
}
super.doAppend(eventObject);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package ch.qos.logback.ext.graalvm.appenders;

import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.spi.ILoggingEvent;

/**
* Lazy async appender with worker initialization on start phase.
*/
public class LazyAsyncAppender extends LazyAsyncAppenderBase<ILoggingEvent> {

boolean includeCallerData = false;

/**
* Events of level TRACE, DEBUG and INFO are deemed to be discardable.
*
* @param event
* @return true if the event is of level TRACE, DEBUG or INFO false otherwise.
*/
protected boolean isDiscardable(ILoggingEvent event) {
Level level = event.getLevel();
return level.toInt() <= Level.INFO_INT;
}

protected void preprocess(ILoggingEvent eventObject) {
eventObject.prepareForDeferredProcessing();
if (includeCallerData)
eventObject.getCallerData();
}

public boolean isIncludeCallerData() {
return includeCallerData;
}

public void setIncludeCallerData(boolean includeCallerData) {
this.includeCallerData = includeCallerData;
}

}
Loading