From 21991f261c8c72b87e23525ae2a3041a6a2cbbba Mon Sep 17 00:00:00 2001 From: Steven Williams Date: Tue, 7 Jan 2025 20:58:34 -0500 Subject: [PATCH] Fix class loader issue Use the main thread's context class loader (rather than the system class loader) to resolve logback-cli.xml from the classpath. Otherwise resolution fails in a Spring Boot `repackage`d fat JAR, because the system class loader doesn't support reaching into nested JARs to find resources. --- .../measureeval/FileSystemInvocation.java | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/Java/measureeval/src/main/java/com/lantanagroup/link/measureeval/FileSystemInvocation.java b/Java/measureeval/src/main/java/com/lantanagroup/link/measureeval/FileSystemInvocation.java index 5a866113..17d98c46 100644 --- a/Java/measureeval/src/main/java/com/lantanagroup/link/measureeval/FileSystemInvocation.java +++ b/Java/measureeval/src/main/java/com/lantanagroup/link/measureeval/FileSystemInvocation.java @@ -16,6 +16,7 @@ import java.io.File; import java.io.IOException; +import java.net.URL; import java.util.ArrayList; import java.util.HashSet; import java.util.List; @@ -33,13 +34,23 @@ public class FileSystemInvocation { private static final FhirContext fhirContext = FhirContext.forR4Cached(); private static final Logger logger = LoggerFactory.getLogger(FileSystemInvocation.class); - private static void configureLogging(Bundle bundle) throws JoranException { - LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory(); - context.reset(); - JoranConfigurator configurator = new JoranConfigurator(); - configurator.setContext(context); - configurator.doConfigure(ClassLoader.getSystemResource("logback-cli.xml")); - CqlLogAppender.start(context, libraryId -> CqlUtils.getLibrary(bundle, libraryId)); + private static void configureLogging(Bundle bundle) { + try { + LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory(); + context.reset(); + JoranConfigurator configurator = new JoranConfigurator(); + configurator.setContext(context); + ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); + URL resource = classLoader.getResource("logback-cli.xml"); + if (resource == null) { + logger.warn("logback-cli.xml not found in classpath"); + return; + } + configurator.doConfigure(resource); + CqlLogAppender.start(context, libraryId -> CqlUtils.getLibrary(bundle, libraryId)); + } catch (Exception e) { + logger.warn("Failed to configure logging", e); + } } private static Bundle getBundle(String measureBundlePath) throws IOException {