Skip to content

Commit

Permalink
fix binary compat and address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
aajtodd committed Sep 27, 2023
1 parent 079348f commit 0e66d4a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ apiValidation {
"paginator-tests",
"waiter-tests",
"compile",
"slf4j-1x-consumer",
"slf4j-2x-consumer",
),
)
}
4 changes: 2 additions & 2 deletions runtime/observability/logging-slf4j2/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}

0 comments on commit 0e66d4a

Please sign in to comment.