Skip to content

Commit 179fc5f

Browse files
committed
Suppress readExcel StatusLogger from log4j in 2025.2.4 notebooks
1 parent 4fd5602 commit 179fc5f

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

dataframe-jupyter/build.gradle.kts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ repositories {
2323
dependencies {
2424
api(projects.dataframe)
2525

26-
// logger, need it for apache poi
27-
implementation(libs.log4j.core)
28-
implementation(libs.log4j.api)
29-
3026
testImplementation(libs.junit)
3127
testImplementation(libs.serialization.json)
3228

dataframe-jupyter/src/main/kotlin/org/jetbrains/kotlinx/dataframe/jupyter/Integration.kt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,14 @@ import org.jetbrains.kotlinx.jupyter.api.KotlinKernelHost
4646
import org.jetbrains.kotlinx.jupyter.api.Notebook
4747
import org.jetbrains.kotlinx.jupyter.api.VariableName
4848
import org.jetbrains.kotlinx.jupyter.api.declare
49+
import org.jetbrains.kotlinx.jupyter.api.dependencies.DependencyDescription
50+
import org.jetbrains.kotlinx.jupyter.api.dependencies.ResolutionResult
4951
import org.jetbrains.kotlinx.jupyter.api.libraries.ColorScheme
5052
import org.jetbrains.kotlinx.jupyter.api.libraries.FieldHandlerFactory
5153
import org.jetbrains.kotlinx.jupyter.api.libraries.JupyterIntegration
5254
import org.jetbrains.kotlinx.jupyter.api.libraries.resources
55+
import org.jetbrains.kotlinx.jupyter.util.ModifiableParentsClassLoader
56+
import java.net.URLClassLoader
5357
import kotlin.reflect.KClass
5458
import kotlin.reflect.KProperty
5559
import kotlin.reflect.KType
@@ -200,6 +204,9 @@ internal class Integration(private val notebook: Notebook, private val options:
200204
declare("dataFrameConfig" to config)
201205
}
202206

207+
// Needed to suppress ERROR Log4j API could not find a logging provider in 2025.2.4
208+
loadLog4jIntoNotebookClasspath(notebook)
209+
203210
resources {
204211
if (!config.display.isolatedOutputs) {
205212
js("DataFrame") {
@@ -349,6 +356,28 @@ internal class Integration(private val notebook: Notebook, private val options:
349356
}
350357
}
351358

359+
// https://github.com/Kotlin/kotlin-notebook-integrations/blob/master/integrations/database/database-api/src/main/kotlin/org/jetbrains/kotlinx/jupyter/database/internal/drivers/ExternalDependencyDriverLoader.kt
360+
internal fun loadLog4jIntoNotebookClasspath(notebook: Notebook) {
361+
val customizableClassLoader = notebook.intermediateClassLoader as? ModifiableParentsClassLoader ?: return
362+
363+
val resolver = notebook.dependencyManager.resolver
364+
365+
val resolutionResult = resolver.resolve(
366+
listOf(
367+
DependencyDescription("org.apache.logging.log4j:log4j-core:2.24.3"),
368+
DependencyDescription("org.apache.logging.log4j:log4j-api:2.24.3")
369+
)
370+
)
371+
372+
val resolvedJars = when (resolutionResult) {
373+
is ResolutionResult.Success -> resolutionResult.binaryClasspath
374+
is ResolutionResult.Failure -> return
375+
}
376+
377+
val urlClassLoader = URLClassLoader(resolvedJars.map { it.toURI().toURL() }.toTypedArray())
378+
customizableClassLoader.addParent(urlClassLoader)
379+
}
380+
352381
public fun KotlinKernelHost.useSchemas(schemaClasses: Iterable<KClass<*>>) {
353382
newDataSchemas.addAll(schemaClasses)
354383
}

0 commit comments

Comments
 (0)