Replies: 3 comments 7 replies
-
First of all, thanks for taking up this initiative! Can we not include the reflection/reachability metadata in the module itself? |
Beta Was this translation helpful? Give feedback.
-
Providing GraalVM support is not only going to be about providing reflection/reachability metadata, but also might require rewriting parts of Log4j that GraalVM does not agree with (and reflection/reachability metedata can't fix) or to provide substitution code that replaces these parts when using GraalVM. I indicate this because I encountered such a case while implementating GraalVM support for the log4j-api for a GraalVM test application. When starting a GraalVM compiled native binary, it failed to initialise Log4J because of the import java.lang.invoke.MethodHandles.Lookup;
import java.util.Collections;
import java.util.ServiceLoader;
import com.oracle.svm.core.annotate.Substitute;
import com.oracle.svm.core.annotate.TargetClass;
import org.apache.logging.log4j.status.StatusLogger;
/**
* This class should be considered internal.
*/
@TargetClass(org.apache.logging.log4j.util.ServiceLoaderUtil.class)
public final class Log4jUtilServiceLoaderUtil {
@Substitute
static <T> Iterable<T> callServiceLoader(Lookup lookup, Class<T> serviceType, ClassLoader classLoader,
boolean verbose) {
System.out.println("Loading with service loader: " + serviceType);
try {
return ServiceLoader.load(serviceType, classLoader);
} catch (Throwable e) {
if (verbose) {
StatusLogger.getLogger().error("Unable to load services for service {}", serviceType, e);
}
}
return Collections.emptyList();
}
} |
Beta Was this translation helpful? Give feedback.
-
A small update on this subject: Log4j Core However, if you wish to optimize your executable for size (e.g. leave only Socket Appender and JSON Template Layout and drop everything else) you will still be able to do it. |
Beta Was this translation helpful? Give feedback.
-
Since
log4j-api
andlog4j-core
heavily rely on reflection, GraalVM users need to provide a lot of reachability metadata in their applications.Right now there are already tools that help users in compiling this metadata:
These tools are blunt instruments and they add to the binary code generated by GraalVM all the possible components that a user can employ in a Log4j Core configuration. This behavior eliminates one of the main advantages of Log4j Core's architecture: Log4j Core is modular, therefore it is possible for users to cherry pick the list of components that they want to use in their native application and remove the rest of the code.
The big question is how to choose this list of components? I am opening this discussion to allow users to express their expectation regarding the usage of Log4j Core in a native application:
Beta Was this translation helpful? Give feedback.
All reactions