diff --git a/build.gradle.kts b/build.gradle.kts index 722fb9c8e..ccd3c008b 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -127,6 +127,8 @@ apiValidation { "paginator-tests", "waiter-tests", "compile", + "slf4j-1x-consumer", + "slf4j-2x-consumer", ), ) } diff --git a/runtime/observability/logging-slf4j2/build.gradle.kts b/runtime/observability/logging-slf4j2/build.gradle.kts index 477d52e17..2fd9ad4c7 100644 --- a/runtime/observability/logging-slf4j2/build.gradle.kts +++ b/runtime/observability/logging-slf4j2/build.gradle.kts @@ -2,8 +2,8 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ -description = "Logging provider based on SLF4J 2.x" -extra["displayName"] = "Smithy :: Kotlin :: Observability :: SLF4J2 binding" +description = "Logging provider based on SLF4J" +extra["displayName"] = "Smithy :: Kotlin :: Observability :: SLF4J binding" extra["moduleName"] = "aws.smithy.kotlin.runtime.telemetry" kotlin { diff --git a/runtime/observability/logging-slf4j2/jvm/src/aws/smithy/kotlin/runtime/telemetry/logging/slf4j/Slf4jLoggerProvider.kt b/runtime/observability/logging-slf4j2/jvm/src/aws/smithy/kotlin/runtime/telemetry/logging/slf4j/Slf4jLoggerProvider.kt index 0d41f5de2..44fff639e 100644 --- a/runtime/observability/logging-slf4j2/jvm/src/aws/smithy/kotlin/runtime/telemetry/logging/slf4j/Slf4jLoggerProvider.kt +++ b/runtime/observability/logging-slf4j2/jvm/src/aws/smithy/kotlin/runtime/telemetry/logging/slf4j/Slf4jLoggerProvider.kt @@ -13,16 +13,20 @@ import org.slf4j.LoggerFactory */ public object Slf4jLoggerProvider : LoggerProvider { - private val slf4jLoggerAdapter: (org.slf4j.Logger) -> Logger = try { + private val useSlf4j2x = try { Class.forName("org.slf4j.spi.LoggingEventBuilder") - ::Slf4j2xLoggerAdapter + true } catch (ex: ClassNotFoundException) { LoggerFactory.getLogger(Slf4jLoggerProvider::class.java).warn("falling back to SLF4J 1.x compatible binding") - ::Slf4j1xLoggerAdapter + false } override fun getOrCreateLogger(name: String): Logger { val sl4fjLogger = LoggerFactory.getLogger(name) - return slf4jLoggerAdapter(sl4fjLogger) + return if (useSlf4j2x) { + Slf4j2xLoggerAdapter(sl4fjLogger) + } else { + Slf4j1xLoggerAdapter(sl4fjLogger) + } } }