Skip to content

Commit

Permalink
add constant logger
Browse files Browse the repository at this point in the history
  • Loading branch information
oshai committed Aug 8, 2023
1 parent aecfeb8 commit a979f2e
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,26 @@ package io.github.oshai.kotlinlogging.internal
import io.github.oshai.kotlinlogging.DarwinKLogger
import io.github.oshai.kotlinlogging.KLogger
import io.github.oshai.kotlinlogging.KotlinLoggingConfiguration
import kotlin.native.concurrent.AtomicReference
import platform.darwin.OS_LOG_DEFAULT
import platform.darwin.os_log_create

/** factory methods to obtain a [KLogger] */
internal actual object KLoggerFactory {

private val constantLogger: AtomicReference<KLogger?> = AtomicReference(null)

/** get logger by explicit name */
internal actual fun logger(name: String): KLogger {
val subsystemConfigured = KotlinLoggingConfiguration.subsystem.value
val categoryConfigured = KotlinLoggingConfiguration.category.value
return when {
subsystemConfigured != null && categoryConfigured != null -> {
constantLogger.value
?: DarwinKLogger(name, os_log_create(subsystemConfigured, categoryConfigured)).also {
constantLogger.value = it
}
}
subsystemConfigured != null || categoryConfigured != null -> {
DarwinKLogger(name, os_log_create(subsystemConfigured ?: name, categoryConfigured ?: name))
}
Expand Down

0 comments on commit a979f2e

Please sign in to comment.