Skip to content

Commit 8ab1a8a

Browse files
authored
Fix GraalVM native build error caused by stale substitution target in v8.x (#601)
Fix GraalVM native build error caused by stale substitution target in v8.x Context In kotlin-logging v8.x, io.github.oshai.kotlinlogging.internal.KLoggerFactory was moved to io.github.oshai.kotlinlogging.KotlinLoggingConfiguration, but the GraalVM @TargetClass substitution still referenced the old internal class. When Logback is absent from the native image classpath, the LogbackNotOnClasspath condition activates the substitution — which then fails because the target class no longer exists at that location. This PR updates the GraalVM substitution to align with the 8.x architecture while preserving core configuration overrides. Changes Renamed Target_io_github_oshai_kotlinlogging_internal_KLoggerFactory.kt → Target_io_github_oshai_kotlinlogging_KotlinLoggingConfiguration.kt (following standard naming conventions). Updated @TargetClass to target the new io.github.oshai.kotlinlogging.KotlinLoggingConfiguration class. Substituted detectLogger() (instead of the old logger method) to bypass LogbackLoggerFactory initialization when Logback is missing. This prevents GraalVM static analysis from failing on missing Logback imports (like LoggerContext). Preserved JVM System Property Overrides: The substituted detectLogger() method correctly retains support for both the kotlin-logging-to-jul and kotlin-logging-to-direct system property overrides, as both JulLoggerFactory and DirectLoggerFactory (residing in commonMain) are completely safe for GraalVM to resolve even when Logback is absent. Verification Ran ./gradlew jvmTest to verify SLF4J/JUL fallback paths pass successfully. Ran ./gradlew logbackTest to verify standard paths when Logback is present pass successfully.
1 parent b1eb9fc commit 8ab1a8a

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

src/jvmMain/kotlin/io/github/oshai/kotlinlogging/internal/Target_io_github_oshai_kotlinlogging_internal_KLoggerFactory.kt renamed to src/jvmMain/kotlin/io/github/oshai/kotlinlogging/internal/Target_io_github_oshai_kotlinlogging_KotlinLoggingConfiguration.kt

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ package io.github.oshai.kotlinlogging.internal
33
import com.oracle.svm.core.annotate.Substitute
44
import com.oracle.svm.core.annotate.TargetClass
55
import com.oracle.svm.core.annotate.TargetElement
6-
import io.github.oshai.kotlinlogging.KLogger
6+
import io.github.oshai.kotlinlogging.DirectLoggerFactory
7+
import io.github.oshai.kotlinlogging.KLoggerFactory
78
import io.github.oshai.kotlinlogging.jul.internal.JulLoggerFactory
89
import io.github.oshai.kotlinlogging.slf4j.internal.Slf4jLoggerFactory
910
import java.util.function.BooleanSupplier
@@ -16,21 +17,23 @@ import java.util.function.BooleanSupplier
1617
* to convention.
1718
*/
1819
@Suppress("unused")
19-
internal class Target_io_github_oshai_kotlinlogging_internal_KLoggerFactory {
20+
internal class Target_io_github_oshai_kotlinlogging_KotlinLoggingConfiguration {
2021
@TargetClass(
21-
className = "io.github.oshai.kotlinlogging.internal.KLoggerFactory",
22+
className = "io.github.oshai.kotlinlogging.KotlinLoggingConfiguration",
2223
onlyWith = [LogbackNotOnClasspath::class],
2324
)
2425
companion object {
2526
@Substitute
26-
@TargetElement(name = "logger\$kotlin_logging")
27-
fun logger(name: String): KLogger {
27+
@TargetElement(name = "detectLogger")
28+
fun detectLogger(): KLoggerFactory {
2829
if (System.getProperty("kotlin-logging-to-jul") != null) {
29-
return JulLoggerFactory.wrapJLogger(JulLoggerFactory.jLogger(name))
30+
return JulLoggerFactory
31+
} else if (System.getProperty("kotlin-logging-to-direct") == "true") {
32+
return DirectLoggerFactory
3033
}
3134
// Intentionally leave out the logback branch as logback is not on the classpath.
3235
// default to SLF4J
33-
return Slf4jLoggerFactory.wrapJLogger(Slf4jLoggerFactory.jLogger(name))
36+
return Slf4jLoggerFactory
3437
}
3538
}
3639
}

0 commit comments

Comments
 (0)