diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index b3ceb68e..f6a143ba 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -4,6 +4,7 @@ on: push: branches: - github-release + - github-release-4.x jobs: release: @@ -16,12 +17,12 @@ jobs: with: java-version: 11 - name: Publish - run: ./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository -no-daemon --no-parallel --stacktrace -DSONATYPE_USERNAME=$SONATYPE_USERNAME -DSONATYPE_PASSWORD=$SONATYPE_PASSWORD -DGPG_PRIVATE_PASSWORD=$GPG_PRIVATE_PASSWORD -DGPG_PRIVATE_KEY=$GPG_PRIVATE_KEY + run: ./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository -no-daemon --no-parallel --stacktrace -DSONATYPE_USERNAME_2=$SONATYPE_USERNAME_2 -DSONATYPE_PASSWORD_2=$SONATYPE_PASSWORD_2 -DGPG_PRIVATE_PASSWORD=$GPG_PRIVATE_PASSWORD -DGPG_PRIVATE_KEY=$GPG_PRIVATE_KEY env: - SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} - SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} + SONATYPE_USERNAME_2: ${{ secrets.SONATYPE_USERNAME_2 }} + SONATYPE_PASSWORD_2: ${{ secrets.SONATYPE_PASSWORD_2 }} SONATYPE_REPOSITORY_ID: ${{ needs.create_staging_repository.outputs.repository_id }} GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }} GPG_PRIVATE_PASSWORD: ${{ secrets.GPG_PRIVATE_PASSWORD }} - ORG_GRADLE_PROJECT_sonatypePassword: ${{ secrets.SONATYPE_PASSWORD }} - ORG_GRADLE_PROJECT_sonatypeUsername: ${{ secrets.SONATYPE_USERNAME }} + ORG_GRADLE_PROJECT_sonatypePassword: ${{ secrets.SONATYPE_PASSWORD_2 }} + ORG_GRADLE_PROJECT_sonatypeUsername: ${{ secrets.SONATYPE_USERNAME_2 }} diff --git a/build.gradle.kts b/build.gradle.kts index 656053be..17f083ff 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -15,8 +15,8 @@ plugins { apply("versions.gradle.kts") -group = "io.github.microutils" -version = "3.0.6" +group = "io.github.oshai" +version = "4.0.0-beta-10" repositories { mavenCentral() @@ -24,7 +24,12 @@ repositories { nexusPublishing { repositories { - sonatype() + sonatype { //only for users registered in Sonatype after 24 Feb 2021 + nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/")) + snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")) + username.set(System.getenv("SONATYPE_USERNAME_2")) // defaults to project.properties["myNexusUsername"] + password.set(System.getenv("SONATYPE_PASSWORD_2")) // defaults to project.properties["myNexusPassword"] + } } } @@ -82,7 +87,7 @@ kotlin { } val jvmMain by getting { dependencies { - api("org.slf4j:slf4j-api:${extra["slf4j_version"]}") + compileOnly("org.slf4j:slf4j-api:${extra["slf4j_version"]}") } } val jvmTest by getting { @@ -94,6 +99,9 @@ kotlin { implementation("org.apache.logging.log4j:log4j-api:${extra["log4j_version"]}") implementation("org.apache.logging.log4j:log4j-core:${extra["log4j_version"]}") implementation("org.apache.logging.log4j:log4j-slf4j2-impl:${extra["log4j_version"]}") + implementation("org.slf4j:slf4j-api:${extra["slf4j_version"]}") + // our jul test just forward the logs jul -> slf4j -> log4j + implementation("org.slf4j:jul-to-slf4j:${extra["slf4j_version"]}") } } val jsMain by getting {} @@ -218,6 +226,6 @@ detekt { val jvmJar by tasks.getting(Jar::class) { manifest { - attributes("Automatic-Module-Name" to "io.github.microutils.kotlinlogging") + attributes("Automatic-Module-Name" to "io.github.oshai.kotlinlogging") } } diff --git a/gradle.properties b/gradle.properties index b8cc320b..3cc223ff 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,3 @@ -kotlin.mpp.enableGranularSourceSetsMetadata=true kotlin.mpp.stability.nowarn=true kotlin.native.ignoreDisabledTargets=true # workaround for https://github.com/gradle/gradle/issues/11412 diff --git a/settings.gradle.kts b/settings.gradle.kts index ffa4ea8e..be23a0dc 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,7 +1,6 @@ pluginManagement { repositories { gradlePluginPortal() - jcenter() } } diff --git a/src/commonMain/kotlin/mu/KLogger.kt b/src/commonMain/kotlin/io/github/oshai/KLogger.kt similarity index 74% rename from src/commonMain/kotlin/mu/KLogger.kt rename to src/commonMain/kotlin/io/github/oshai/KLogger.kt index 40fe930e..82302d2d 100644 --- a/src/commonMain/kotlin/mu/KLogger.kt +++ b/src/commonMain/kotlin/io/github/oshai/KLogger.kt @@ -1,7 +1,13 @@ -package mu +package io.github.oshai public expect interface KLogger { + /** + * Return the name of this `Logger` instance. + * @return name of this logger instance + */ + public val name: String + /** Lazy add a log message if isTraceEnabled is true */ public fun trace(msg: () -> Any?) @@ -33,34 +39,34 @@ public expect interface KLogger { public fun error(t: Throwable?, msg: () -> Any?) /** Lazy add a log message with a marker if isTraceEnabled is true */ - public fun trace(marker: Marker?, msg: () -> Any?) + public fun trace(marker: io.github.oshai.Marker?, msg: () -> Any?) /** Lazy add a log message with a marker if isDebugEnabled is true */ - public fun debug(marker: Marker?, msg: () -> Any?) + public fun debug(marker: io.github.oshai.Marker?, msg: () -> Any?) /** Lazy add a log message with a marker if isInfoEnabled is true */ - public fun info(marker: Marker?, msg: () -> Any?) + public fun info(marker: io.github.oshai.Marker?, msg: () -> Any?) /** Lazy add a log message with a marker if isWarnEnabled is true */ - public fun warn(marker: Marker?, msg: () -> Any?) + public fun warn(marker: io.github.oshai.Marker?, msg: () -> Any?) /** Lazy add a log message with a marker if isErrorEnabled is true */ - public fun error(marker: Marker?, msg: () -> Any?) + public fun error(marker: io.github.oshai.Marker?, msg: () -> Any?) /** Lazy add a log message with a marker and throwable payload if isTraceEnabled is true */ - public fun trace(marker: Marker?, t: Throwable?, msg: () -> Any?) + public fun trace(marker: io.github.oshai.Marker?, t: Throwable?, msg: () -> Any?) /** Lazy add a log message with a marker and throwable payload if isDebugEnabled is true */ - public fun debug(marker: Marker?, t: Throwable?, msg: () -> Any?) + public fun debug(marker: io.github.oshai.Marker?, t: Throwable?, msg: () -> Any?) /** Lazy add a log message with a marker and throwable payload if isInfoEnabled is true */ - public fun info(marker: Marker?, t: Throwable?, msg: () -> Any?) + public fun info(marker: io.github.oshai.Marker?, t: Throwable?, msg: () -> Any?) /** Lazy add a log message with a marker and throwable payload if isWarnEnabled is true */ - public fun warn(marker: Marker?, t: Throwable?, msg: () -> Any?) + public fun warn(marker: io.github.oshai.Marker?, t: Throwable?, msg: () -> Any?) /** Lazy add a log message with a marker and throwable payload if isErrorEnabled is true */ - public fun error(marker: Marker?, t: Throwable?, msg: () -> Any?) + public fun error(marker: io.github.oshai.Marker?, t: Throwable?, msg: () -> Any?) /** Add a log message with all the supplied parameters along with method name */ public fun entry(vararg argArray: Any?) diff --git a/src/commonMain/kotlin/io/github/oshai/KMarkerFactory.kt b/src/commonMain/kotlin/io/github/oshai/KMarkerFactory.kt new file mode 100644 index 00000000..d867ae37 --- /dev/null +++ b/src/commonMain/kotlin/io/github/oshai/KMarkerFactory.kt @@ -0,0 +1,7 @@ +package io.github.oshai + +/** A platform independent factory to create markers. */ +public object KMarkerFactory { + + public fun getMarker(name: String): io.github.oshai.Marker = io.github.oshai.SimpleMarker(name) +} diff --git a/src/commonMain/kotlin/mu/KotlinLogging.kt b/src/commonMain/kotlin/io/github/oshai/KotlinLogging.kt similarity index 56% rename from src/commonMain/kotlin/mu/KotlinLogging.kt rename to src/commonMain/kotlin/io/github/oshai/KotlinLogging.kt index bf420039..83b53e57 100644 --- a/src/commonMain/kotlin/mu/KotlinLogging.kt +++ b/src/commonMain/kotlin/io/github/oshai/KotlinLogging.kt @@ -1,4 +1,4 @@ -package mu +package io.github.oshai public expect object KotlinLogging { /** @@ -7,7 +7,7 @@ public expect object KotlinLogging { * val logger = KotlinLogging.logger {} * ``` */ - public fun logger(func: () -> Unit): KLogger + public fun logger(func: () -> Unit): io.github.oshai.KLogger - public fun logger(name: String): KLogger + public fun logger(name: String): io.github.oshai.KLogger } diff --git a/src/commonMain/kotlin/io/github/oshai/Level.kt b/src/commonMain/kotlin/io/github/oshai/Level.kt new file mode 100644 index 00000000..894961a1 --- /dev/null +++ b/src/commonMain/kotlin/io/github/oshai/Level.kt @@ -0,0 +1,39 @@ +package io.github.oshai + +public enum class Level(private val levelInt: Int, private val levelStr: String) { + TRACE(io.github.oshai.Levels.TRACE_INT, "TRACE"), + DEBUG(io.github.oshai.Levels.DEBUG_INT, "DEBUG"), + INFO(io.github.oshai.Levels.INFO_INT, "INFO"), + WARN(io.github.oshai.Levels.WARN_INT, "WARN"), + ERROR(io.github.oshai.Levels.ERROR_INT, "ERROR"), + ; + + public fun toInt(): Int { + return levelInt + } + + /** Returns the string representation of this Level. */ + override fun toString(): String { + return levelStr + } +} + +public object Levels { + + public const val TRACE_INT: Int = 0 + public const val DEBUG_INT: Int = 10 + public const val INFO_INT: Int = 20 + public const val WARN_INT: Int = 30 + public const val ERROR_INT: Int = 40 + + public fun intToLevel(levelInt: Int): io.github.oshai.Level { + return when (levelInt) { + io.github.oshai.Levels.TRACE_INT -> io.github.oshai.Level.TRACE + io.github.oshai.Levels.DEBUG_INT -> io.github.oshai.Level.DEBUG + io.github.oshai.Levels.INFO_INT -> io.github.oshai.Level.INFO + io.github.oshai.Levels.WARN_INT -> io.github.oshai.Level.WARN + io.github.oshai.Levels.ERROR_INT -> io.github.oshai.Level.ERROR + else -> throw IllegalArgumentException("Level integer [$levelInt] not recognized.") + } + } +} diff --git a/src/commonMain/kotlin/io/github/oshai/Marker.kt b/src/commonMain/kotlin/io/github/oshai/Marker.kt new file mode 100644 index 00000000..f0e57f79 --- /dev/null +++ b/src/commonMain/kotlin/io/github/oshai/Marker.kt @@ -0,0 +1,11 @@ +package io.github.oshai + +/** A platform independent marker to enrich log statements. */ +public interface Marker { + + public fun getName(): String +} + +internal data class SimpleMarker(private val name: String) : io.github.oshai.Marker { + override fun getName(): String = this.name +} diff --git a/src/commonMain/kotlin/mu/internal/MessageInvoker.kt b/src/commonMain/kotlin/io/github/oshai/internal/MessageInvoker.kt similarity index 89% rename from src/commonMain/kotlin/mu/internal/MessageInvoker.kt rename to src/commonMain/kotlin/io/github/oshai/internal/MessageInvoker.kt index 6242f226..be54eb6c 100644 --- a/src/commonMain/kotlin/mu/internal/MessageInvoker.kt +++ b/src/commonMain/kotlin/io/github/oshai/internal/MessageInvoker.kt @@ -1,4 +1,4 @@ -package mu.internal +package io.github.oshai.internal @Suppress("NOTHING_TO_INLINE") internal inline fun (() -> Any?).toStringSafe(): String { diff --git a/src/commonMain/kotlin/mu/KMarkerFactory.kt b/src/commonMain/kotlin/mu/KMarkerFactory.kt deleted file mode 100644 index eeea2eb4..00000000 --- a/src/commonMain/kotlin/mu/KMarkerFactory.kt +++ /dev/null @@ -1,7 +0,0 @@ -package mu - -/** A platform independent factory to create markers. */ -public expect object KMarkerFactory { - - public fun getMarker(name: String): Marker -} diff --git a/src/commonMain/kotlin/mu/Marker.kt b/src/commonMain/kotlin/mu/Marker.kt deleted file mode 100644 index f21cfe5a..00000000 --- a/src/commonMain/kotlin/mu/Marker.kt +++ /dev/null @@ -1,7 +0,0 @@ -package mu - -/** A platform independent marker to enrich log statements. */ -public expect interface Marker { - - public fun getName(): String -} diff --git a/src/commonTest/kotlin/mu/SimpleTest.kt b/src/commonTest/kotlin/io/github/oshai/SimpleTest.kt similarity index 55% rename from src/commonTest/kotlin/mu/SimpleTest.kt rename to src/commonTest/kotlin/io/github/oshai/SimpleTest.kt index c5b505c4..2fb3d7cf 100644 --- a/src/commonTest/kotlin/mu/SimpleTest.kt +++ b/src/commonTest/kotlin/io/github/oshai/SimpleTest.kt @@ -1,9 +1,9 @@ -package mu +package io.github.oshai import kotlin.test.Test class SimpleTest { - private val logger = KotlinLogging.logger {} + private val logger = io.github.oshai.KotlinLogging.logger {} @Test fun simpleTest() { diff --git a/src/commonTest/kotlin/mu/internal/MessageInvokerTest.kt b/src/commonTest/kotlin/io/github/oshai/internal/MessageInvokerTest.kt similarity index 89% rename from src/commonTest/kotlin/mu/internal/MessageInvokerTest.kt rename to src/commonTest/kotlin/io/github/oshai/internal/MessageInvokerTest.kt index d456fedc..5224ddc2 100644 --- a/src/commonTest/kotlin/mu/internal/MessageInvokerTest.kt +++ b/src/commonTest/kotlin/io/github/oshai/internal/MessageInvokerTest.kt @@ -1,4 +1,4 @@ -package mu.internal +package io.github.oshai.internal import kotlin.test.Test import kotlin.test.assertEquals diff --git a/src/darwinMain/kotlin/mu/KotlinLoggingConfiguration.kt b/src/darwinMain/kotlin/io/github/oshai/KotlinLoggingConfiguration.kt similarity index 72% rename from src/darwinMain/kotlin/mu/KotlinLoggingConfiguration.kt rename to src/darwinMain/kotlin/io/github/oshai/KotlinLoggingConfiguration.kt index 45053359..ad09480d 100644 --- a/src/darwinMain/kotlin/mu/KotlinLoggingConfiguration.kt +++ b/src/darwinMain/kotlin/io/github/oshai/KotlinLoggingConfiguration.kt @@ -1,3 +1,3 @@ -package mu +package io.github.oshai public actual val DefaultAppender: Appender = OSLogAppender() diff --git a/src/darwinMain/kotlin/mu/OSLogAppender.kt b/src/darwinMain/kotlin/io/github/oshai/OSLogAppender.kt similarity index 98% rename from src/darwinMain/kotlin/mu/OSLogAppender.kt rename to src/darwinMain/kotlin/io/github/oshai/OSLogAppender.kt index 3e31515e..0df8b010 100644 --- a/src/darwinMain/kotlin/mu/OSLogAppender.kt +++ b/src/darwinMain/kotlin/io/github/oshai/OSLogAppender.kt @@ -1,4 +1,4 @@ -package mu +package io.github.oshai import kotlinx.cinterop.ptr import platform.darwin.OS_LOG_DEFAULT diff --git a/src/darwinMain/kotlin/mu/OSLogSubsystemAppender.kt b/src/darwinMain/kotlin/io/github/oshai/OSLogSubsystemAppender.kt similarity index 96% rename from src/darwinMain/kotlin/mu/OSLogSubsystemAppender.kt rename to src/darwinMain/kotlin/io/github/oshai/OSLogSubsystemAppender.kt index d2fdd41e..01fe32d6 100644 --- a/src/darwinMain/kotlin/mu/OSLogSubsystemAppender.kt +++ b/src/darwinMain/kotlin/io/github/oshai/OSLogSubsystemAppender.kt @@ -1,4 +1,4 @@ -package mu +package io.github.oshai import kotlin.native.concurrent.AtomicReference import platform.darwin.os_log_create diff --git a/src/jsMain/kotlin/mu/Appender.kt b/src/jsMain/kotlin/io/github/oshai/Appender.kt similarity index 89% rename from src/jsMain/kotlin/mu/Appender.kt rename to src/jsMain/kotlin/io/github/oshai/Appender.kt index 3082f68a..cf74d27b 100644 --- a/src/jsMain/kotlin/mu/Appender.kt +++ b/src/jsMain/kotlin/io/github/oshai/Appender.kt @@ -1,4 +1,4 @@ -package mu +package io.github.oshai public interface Appender { public fun trace(message: Any?) diff --git a/src/jsMain/kotlin/mu/ConsoleOutputAppender.kt b/src/jsMain/kotlin/io/github/oshai/ConsoleOutputAppender.kt similarity index 94% rename from src/jsMain/kotlin/mu/ConsoleOutputAppender.kt rename to src/jsMain/kotlin/io/github/oshai/ConsoleOutputAppender.kt index da6b3fe3..9fb8bddd 100644 --- a/src/jsMain/kotlin/mu/ConsoleOutputAppender.kt +++ b/src/jsMain/kotlin/io/github/oshai/ConsoleOutputAppender.kt @@ -1,4 +1,4 @@ -package mu +package io.github.oshai public object ConsoleOutputAppender : Appender { public override fun trace(message: Any?): Unit = console.log(message) diff --git a/src/jsMain/kotlin/mu/DefaultMessageFormatter.kt b/src/jsMain/kotlin/io/github/oshai/DefaultMessageFormatter.kt similarity index 75% rename from src/jsMain/kotlin/mu/DefaultMessageFormatter.kt rename to src/jsMain/kotlin/io/github/oshai/DefaultMessageFormatter.kt index 36556a4b..7707f89e 100644 --- a/src/jsMain/kotlin/mu/DefaultMessageFormatter.kt +++ b/src/jsMain/kotlin/io/github/oshai/DefaultMessageFormatter.kt @@ -1,30 +1,27 @@ -package mu +package io.github.oshai -import mu.internal.toStringSafe +import io.github.oshai.internal.toStringSafe public object DefaultMessageFormatter : Formatter { - public override fun formatMessage( - level: KotlinLoggingLevel, - loggerName: String, - msg: () -> Any? - ): String = "${level.name}: [$loggerName] ${msg.toStringSafe()}" + public override fun formatMessage(level: Level, loggerName: String, msg: () -> Any?): String = + "${level.name}: [$loggerName] ${msg.toStringSafe()}" public override fun formatMessage( - level: KotlinLoggingLevel, + level: Level, loggerName: String, t: Throwable?, msg: () -> Any? ): String = "${level.name}: [$loggerName] ${msg.toStringSafe()}${t.throwableToString()}" public override fun formatMessage( - level: KotlinLoggingLevel, + level: Level, loggerName: String, marker: Marker?, msg: () -> Any? ): String = "${level.name}: [$loggerName] ${marker?.getName()} ${msg.toStringSafe()}" public override fun formatMessage( - level: KotlinLoggingLevel, + level: Level, loggerName: String, marker: Marker?, t: Throwable?, diff --git a/src/jsMain/kotlin/io/github/oshai/Formatter.kt b/src/jsMain/kotlin/io/github/oshai/Formatter.kt new file mode 100644 index 00000000..c3f49c4e --- /dev/null +++ b/src/jsMain/kotlin/io/github/oshai/Formatter.kt @@ -0,0 +1,14 @@ +package io.github.oshai + +public interface Formatter { + public fun formatMessage(level: Level, loggerName: String, msg: () -> Any?): Any? + public fun formatMessage(level: Level, loggerName: String, t: Throwable?, msg: () -> Any?): Any? + public fun formatMessage(level: Level, loggerName: String, marker: Marker?, msg: () -> Any?): Any? + public fun formatMessage( + level: Level, + loggerName: String, + marker: Marker?, + t: Throwable?, + msg: () -> Any? + ): Any? +} diff --git a/src/jsMain/kotlin/mu/KLogger.kt b/src/jsMain/kotlin/io/github/oshai/KLogger.kt similarity index 73% rename from src/jsMain/kotlin/mu/KLogger.kt rename to src/jsMain/kotlin/io/github/oshai/KLogger.kt index c6a130b5..45e4ea33 100644 --- a/src/jsMain/kotlin/mu/KLogger.kt +++ b/src/jsMain/kotlin/io/github/oshai/KLogger.kt @@ -1,8 +1,14 @@ -package mu +package io.github.oshai @Suppress("TooManyFunctions") public actual interface KLogger { + /** + * Return the name of this `Logger` instance. + * @return name of this logger instance + */ + public actual val name: String + /** Lazy add a log message if isTraceEnabled is true */ public actual fun trace(msg: () -> Any?) @@ -34,34 +40,34 @@ public actual interface KLogger { public actual fun error(t: Throwable?, msg: () -> Any?) /** Lazy add a log message if isTraceEnabled is true */ - public actual fun trace(marker: Marker?, msg: () -> Any?) + public actual fun trace(marker: io.github.oshai.Marker?, msg: () -> Any?) /** Lazy add a log message if isDebugEnabled is true */ - public actual fun debug(marker: Marker?, msg: () -> Any?) + public actual fun debug(marker: io.github.oshai.Marker?, msg: () -> Any?) /** Lazy add a log message if isInfoEnabled is true */ - public actual fun info(marker: Marker?, msg: () -> Any?) + public actual fun info(marker: io.github.oshai.Marker?, msg: () -> Any?) /** Lazy add a log message if isWarnEnabled is true */ - public actual fun warn(marker: Marker?, msg: () -> Any?) + public actual fun warn(marker: io.github.oshai.Marker?, msg: () -> Any?) /** Lazy add a log message if isErrorEnabled is true */ - public actual fun error(marker: Marker?, msg: () -> Any?) + public actual fun error(marker: io.github.oshai.Marker?, msg: () -> Any?) /** Lazy add a log message with throwable payload if isTraceEnabled is true */ - public actual fun trace(marker: Marker?, t: Throwable?, msg: () -> Any?) + public actual fun trace(marker: io.github.oshai.Marker?, t: Throwable?, msg: () -> Any?) /** Lazy add a log message with throwable payload if isDebugEnabled is true */ - public actual fun debug(marker: Marker?, t: Throwable?, msg: () -> Any?) + public actual fun debug(marker: io.github.oshai.Marker?, t: Throwable?, msg: () -> Any?) /** Lazy add a log message with throwable payload if isInfoEnabled is true */ - public actual fun info(marker: Marker?, t: Throwable?, msg: () -> Any?) + public actual fun info(marker: io.github.oshai.Marker?, t: Throwable?, msg: () -> Any?) /** Lazy add a log message with throwable payload if isWarnEnabled is true */ - public actual fun warn(marker: Marker?, t: Throwable?, msg: () -> Any?) + public actual fun warn(marker: io.github.oshai.Marker?, t: Throwable?, msg: () -> Any?) /** Lazy add a log message with throwable payload if isErrorEnabled is true */ - public actual fun error(marker: Marker?, t: Throwable?, msg: () -> Any?) + public actual fun error(marker: io.github.oshai.Marker?, t: Throwable?, msg: () -> Any?) /** Add a log message with all the supplied parameters along with method name */ public actual fun entry(vararg argArray: Any?) diff --git a/src/jsMain/kotlin/io/github/oshai/KotlinLogging.kt b/src/jsMain/kotlin/io/github/oshai/KotlinLogging.kt new file mode 100644 index 00000000..8480b525 --- /dev/null +++ b/src/jsMain/kotlin/io/github/oshai/KotlinLogging.kt @@ -0,0 +1,16 @@ +package io.github.oshai + +import io.github.oshai.internal.KLoggerJS + +public actual object KotlinLogging { + /** + * This method allows defining the logger in a file in the following way: + * ``` + * val logger = KotlinLogging.logger {} + * ``` + */ + public actual fun logger(func: () -> Unit): io.github.oshai.KLogger = + KLoggerJS(func::class.js.name) + + public actual fun logger(name: String): io.github.oshai.KLogger = KLoggerJS(name) +} diff --git a/src/jsMain/kotlin/mu/KotlinLoggingConfiguration.kt b/src/jsMain/kotlin/io/github/oshai/KotlinLoggingConfiguration.kt similarity index 62% rename from src/jsMain/kotlin/mu/KotlinLoggingConfiguration.kt rename to src/jsMain/kotlin/io/github/oshai/KotlinLoggingConfiguration.kt index f269d2b8..aa10bd10 100644 --- a/src/jsMain/kotlin/mu/KotlinLoggingConfiguration.kt +++ b/src/jsMain/kotlin/io/github/oshai/KotlinLoggingConfiguration.kt @@ -1,7 +1,7 @@ -package mu +package io.github.oshai public object KotlinLoggingConfiguration { - public var LOG_LEVEL: KotlinLoggingLevel = KotlinLoggingLevel.INFO + public var LOG_LEVEL: io.github.oshai.Level = io.github.oshai.Level.INFO public var APPENDER: Appender = ConsoleOutputAppender public var FORMATTER: Formatter = DefaultMessageFormatter } diff --git a/src/jsMain/kotlin/io/github/oshai/KotlinLoggingLevel.kt b/src/jsMain/kotlin/io/github/oshai/KotlinLoggingLevel.kt new file mode 100644 index 00000000..a82ae439 --- /dev/null +++ b/src/jsMain/kotlin/io/github/oshai/KotlinLoggingLevel.kt @@ -0,0 +1,5 @@ +package io.github.oshai + +import io.github.oshai.KotlinLoggingConfiguration.LOG_LEVEL + +public fun io.github.oshai.Level.isLoggingEnabled(): Boolean = this.ordinal >= LOG_LEVEL.ordinal diff --git a/src/jsMain/kotlin/mu/internal/ErrorMessageProducer.kt b/src/jsMain/kotlin/io/github/oshai/internal/ErrorMessageProducer.kt similarity index 80% rename from src/jsMain/kotlin/mu/internal/ErrorMessageProducer.kt rename to src/jsMain/kotlin/io/github/oshai/internal/ErrorMessageProducer.kt index 32da3fba..60fb6c9d 100644 --- a/src/jsMain/kotlin/mu/internal/ErrorMessageProducer.kt +++ b/src/jsMain/kotlin/io/github/oshai/internal/ErrorMessageProducer.kt @@ -1,4 +1,4 @@ -package mu.internal +package io.github.oshai.internal public actual object ErrorMessageProducer { public actual fun getErrorLog(e: Exception): String = "Log message invocation failed: $e" diff --git a/src/jsMain/kotlin/mu/internal/KLoggerJS.kt b/src/jsMain/kotlin/io/github/oshai/internal/KLoggerJS.kt similarity index 57% rename from src/jsMain/kotlin/mu/internal/KLoggerJS.kt rename to src/jsMain/kotlin/io/github/oshai/internal/KLoggerJS.kt index 41d689fc..4d105e8e 100644 --- a/src/jsMain/kotlin/mu/internal/KLoggerJS.kt +++ b/src/jsMain/kotlin/io/github/oshai/internal/KLoggerJS.kt @@ -1,19 +1,18 @@ -package mu.internal - -import mu.KLogger -import mu.KotlinLoggingConfiguration.APPENDER -import mu.KotlinLoggingConfiguration.FORMATTER -import mu.KotlinLoggingLevel -import mu.KotlinLoggingLevel.DEBUG -import mu.KotlinLoggingLevel.ERROR -import mu.KotlinLoggingLevel.INFO -import mu.KotlinLoggingLevel.TRACE -import mu.KotlinLoggingLevel.WARN -import mu.Marker -import mu.isLoggingEnabled +package io.github.oshai.internal + +import io.github.oshai.KLogger +import io.github.oshai.KotlinLoggingConfiguration.APPENDER +import io.github.oshai.KotlinLoggingConfiguration.FORMATTER +import io.github.oshai.Level +import io.github.oshai.Level.DEBUG +import io.github.oshai.Level.ERROR +import io.github.oshai.Level.INFO +import io.github.oshai.Level.TRACE +import io.github.oshai.Level.WARN +import io.github.oshai.isLoggingEnabled @Suppress("TooManyFunctions") -internal class KLoggerJS(private val loggerName: String) : KLogger { +internal class KLoggerJS(override val name: String) : KLogger { override fun trace(msg: () -> Any?) = TRACE.logIfEnabled(msg, APPENDER::trace) @@ -35,70 +34,70 @@ internal class KLoggerJS(private val loggerName: String) : KLogger { override fun error(t: Throwable?, msg: () -> Any?) = ERROR.logIfEnabled(msg, t, APPENDER::error) - override fun trace(marker: Marker?, msg: () -> Any?) = + override fun trace(marker: io.github.oshai.Marker?, msg: () -> Any?) = TRACE.logIfEnabled(marker, msg, APPENDER::trace) - override fun debug(marker: Marker?, msg: () -> Any?) = + override fun debug(marker: io.github.oshai.Marker?, msg: () -> Any?) = DEBUG.logIfEnabled(marker, msg, APPENDER::debug) - override fun info(marker: Marker?, msg: () -> Any?) = + override fun info(marker: io.github.oshai.Marker?, msg: () -> Any?) = INFO.logIfEnabled(marker, msg, APPENDER::info) - override fun warn(marker: Marker?, msg: () -> Any?) = + override fun warn(marker: io.github.oshai.Marker?, msg: () -> Any?) = WARN.logIfEnabled(marker, msg, APPENDER::warn) - override fun error(marker: Marker?, msg: () -> Any?) = + override fun error(marker: io.github.oshai.Marker?, msg: () -> Any?) = ERROR.logIfEnabled(marker, msg, APPENDER::error) - override fun trace(marker: Marker?, t: Throwable?, msg: () -> Any?) = + override fun trace(marker: io.github.oshai.Marker?, t: Throwable?, msg: () -> Any?) = TRACE.logIfEnabled(marker, msg, t, APPENDER::trace) - override fun debug(marker: Marker?, t: Throwable?, msg: () -> Any?) = + override fun debug(marker: io.github.oshai.Marker?, t: Throwable?, msg: () -> Any?) = DEBUG.logIfEnabled(marker, msg, t, APPENDER::debug) - override fun info(marker: Marker?, t: Throwable?, msg: () -> Any?) = + override fun info(marker: io.github.oshai.Marker?, t: Throwable?, msg: () -> Any?) = INFO.logIfEnabled(marker, msg, t, APPENDER::info) - override fun warn(marker: Marker?, t: Throwable?, msg: () -> Any?) = + override fun warn(marker: io.github.oshai.Marker?, t: Throwable?, msg: () -> Any?) = WARN.logIfEnabled(marker, msg, t, APPENDER::warn) - override fun error(marker: Marker?, t: Throwable?, msg: () -> Any?) = + override fun error(marker: io.github.oshai.Marker?, t: Throwable?, msg: () -> Any?) = ERROR.logIfEnabled(marker, msg, t, APPENDER::error) - private fun KotlinLoggingLevel.logIfEnabled(msg: () -> Any?, logFunction: (Any?) -> Unit) { + private fun io.github.oshai.Level.logIfEnabled(msg: () -> Any?, logFunction: (Any?) -> Unit) { if (isLoggingEnabled()) { - logFunction(FORMATTER.formatMessage(this, loggerName, msg)) + logFunction(FORMATTER.formatMessage(this, name, msg)) } } - private fun KotlinLoggingLevel.logIfEnabled( + private fun io.github.oshai.Level.logIfEnabled( msg: () -> Any?, t: Throwable?, logFunction: (Any?) -> Unit ) { if (isLoggingEnabled()) { - logFunction(FORMATTER.formatMessage(this, loggerName, t, msg)) + logFunction(FORMATTER.formatMessage(this, name, t, msg)) } } - private fun KotlinLoggingLevel.logIfEnabled( - marker: Marker?, + private fun io.github.oshai.Level.logIfEnabled( + marker: io.github.oshai.Marker?, msg: () -> Any?, logFunction: (Any?) -> Unit ) { if (isLoggingEnabled()) { - logFunction(FORMATTER.formatMessage(this, loggerName, marker, msg)) + logFunction(FORMATTER.formatMessage(this, name, marker, msg)) } } - private fun KotlinLoggingLevel.logIfEnabled( - marker: Marker?, + private fun io.github.oshai.Level.logIfEnabled( + marker: io.github.oshai.Marker?, msg: () -> Any?, t: Throwable?, logFunction: (Any?) -> Unit ) { if (isLoggingEnabled()) { - logFunction(FORMATTER.formatMessage(this, loggerName, marker, t, msg)) + logFunction(FORMATTER.formatMessage(this, name, marker, t, msg)) } } diff --git a/src/jsMain/kotlin/mu/Formatter.kt b/src/jsMain/kotlin/mu/Formatter.kt deleted file mode 100644 index b4b59cc8..00000000 --- a/src/jsMain/kotlin/mu/Formatter.kt +++ /dev/null @@ -1,24 +0,0 @@ -package mu - -public interface Formatter { - public fun formatMessage(level: KotlinLoggingLevel, loggerName: String, msg: () -> Any?): Any? - public fun formatMessage( - level: KotlinLoggingLevel, - loggerName: String, - t: Throwable?, - msg: () -> Any? - ): Any? - public fun formatMessage( - level: KotlinLoggingLevel, - loggerName: String, - marker: Marker?, - msg: () -> Any? - ): Any? - public fun formatMessage( - level: KotlinLoggingLevel, - loggerName: String, - marker: Marker?, - t: Throwable?, - msg: () -> Any? - ): Any? -} diff --git a/src/jsMain/kotlin/mu/KMarkerFactory.kt b/src/jsMain/kotlin/mu/KMarkerFactory.kt deleted file mode 100644 index 45e4a769..00000000 --- a/src/jsMain/kotlin/mu/KMarkerFactory.kt +++ /dev/null @@ -1,8 +0,0 @@ -package mu - -import mu.internal.MarkerJS - -public actual object KMarkerFactory { - - public actual fun getMarker(name: String): Marker = MarkerJS(name) -} diff --git a/src/jsMain/kotlin/mu/KotlinLogging.kt b/src/jsMain/kotlin/mu/KotlinLogging.kt deleted file mode 100644 index 16c5e544..00000000 --- a/src/jsMain/kotlin/mu/KotlinLogging.kt +++ /dev/null @@ -1,15 +0,0 @@ -package mu - -import mu.internal.KLoggerJS - -public actual object KotlinLogging { - /** - * This method allows defining the logger in a file in the following way: - * ``` - * val logger = KotlinLogging.logger {} - * ``` - */ - public actual fun logger(func: () -> Unit): KLogger = KLoggerJS(func::class.js.name) - - public actual fun logger(name: String): KLogger = KLoggerJS(name) -} diff --git a/src/jsMain/kotlin/mu/KotlinLoggingLevel.kt b/src/jsMain/kotlin/mu/KotlinLoggingLevel.kt deleted file mode 100644 index dd5ac335..00000000 --- a/src/jsMain/kotlin/mu/KotlinLoggingLevel.kt +++ /dev/null @@ -1,13 +0,0 @@ -package mu - -import mu.KotlinLoggingConfiguration.LOG_LEVEL - -public enum class KotlinLoggingLevel { - TRACE, - DEBUG, - INFO, - WARN, - ERROR -} - -public fun KotlinLoggingLevel.isLoggingEnabled(): Boolean = this.ordinal >= LOG_LEVEL.ordinal diff --git a/src/jsMain/kotlin/mu/Marker.kt b/src/jsMain/kotlin/mu/Marker.kt deleted file mode 100644 index 87f8f10b..00000000 --- a/src/jsMain/kotlin/mu/Marker.kt +++ /dev/null @@ -1,6 +0,0 @@ -package mu - -public actual interface Marker { - - public actual fun getName(): String -} diff --git a/src/jsMain/kotlin/mu/internal/MarkerJS.kt b/src/jsMain/kotlin/mu/internal/MarkerJS.kt deleted file mode 100644 index c7a945fc..00000000 --- a/src/jsMain/kotlin/mu/internal/MarkerJS.kt +++ /dev/null @@ -1,7 +0,0 @@ -package mu.internal - -import mu.Marker - -internal class MarkerJS(private val name: String) : Marker { - override fun getName(): String = this.name -} diff --git a/src/jvmMain/kotlin/io/github/oshai/KLogger.kt b/src/jvmMain/kotlin/io/github/oshai/KLogger.kt new file mode 100644 index 00000000..cb5c459b --- /dev/null +++ b/src/jvmMain/kotlin/io/github/oshai/KLogger.kt @@ -0,0 +1,696 @@ +package io.github.oshai + +/** + * An Logger interface with Lazy message evaluation example: + * ``` + * logger.info{"this is $lazy evaluated string"} + * ``` + */ +@Suppress("TooManyFunctions") +public actual interface KLogger { + + /** + * Return the name of this `Logger` instance. + * @return name of this logger instance + */ + public actual val name: String + + /** The actual logger executing logging */ + public val underlyingLogger: Any + + /** Lazy add a log message if isTraceEnabled is true */ + public actual fun trace(msg: () -> Any?) + + /** Lazy add a log message if isDebugEnabled is true */ + public actual fun debug(msg: () -> Any?) + + /** Lazy add a log message if isInfoEnabled is true */ + public actual fun info(msg: () -> Any?) + + /** Lazy add a log message if isWarnEnabled is true */ + public actual fun warn(msg: () -> Any?) + + /** Lazy add a log message if isErrorEnabled is true */ + public actual fun error(msg: () -> Any?) + + /** Lazy add a log message with throwable payload if isTraceEnabled is true */ + public actual fun trace(t: Throwable?, msg: () -> Any?) + + /** Lazy add a log message with throwable payload if isDebugEnabled is true */ + public actual fun debug(t: Throwable?, msg: () -> Any?) + + /** Lazy add a log message with throwable payload if isInfoEnabled is true */ + public actual fun info(t: Throwable?, msg: () -> Any?) + + /** Lazy add a log message with throwable payload if isWarnEnabled is true */ + public actual fun warn(t: Throwable?, msg: () -> Any?) + + /** Lazy add a log message with throwable payload if isErrorEnabled is true */ + public actual fun error(t: Throwable?, msg: () -> Any?) + + /** Lazy add a log message if isTraceEnabled is true */ + public actual fun trace(marker: io.github.oshai.Marker?, msg: () -> Any?) + + /** Lazy add a log message if isDebugEnabled is true */ + public actual fun debug(marker: io.github.oshai.Marker?, msg: () -> Any?) + + /** Lazy add a log message if isInfoEnabled is true */ + public actual fun info(marker: io.github.oshai.Marker?, msg: () -> Any?) + + /** Lazy add a log message if isWarnEnabled is true */ + public actual fun warn(marker: io.github.oshai.Marker?, msg: () -> Any?) + + /** Lazy add a log message if isErrorEnabled is true */ + public actual fun error(marker: io.github.oshai.Marker?, msg: () -> Any?) + + /** Lazy add a log message with throwable payload if isTraceEnabled is true */ + public actual fun trace(marker: io.github.oshai.Marker?, t: Throwable?, msg: () -> Any?) + + /** Lazy add a log message with throwable payload if isDebugEnabled is true */ + public actual fun debug(marker: io.github.oshai.Marker?, t: Throwable?, msg: () -> Any?) + + /** Lazy add a log message with throwable payload if isInfoEnabled is true */ + public actual fun info(marker: io.github.oshai.Marker?, t: Throwable?, msg: () -> Any?) + + /** Lazy add a log message with throwable payload if isWarnEnabled is true */ + public actual fun warn(marker: io.github.oshai.Marker?, t: Throwable?, msg: () -> Any?) + + /** Lazy add a log message with throwable payload if isErrorEnabled is true */ + public actual fun error(marker: io.github.oshai.Marker?, t: Throwable?, msg: () -> Any?) + + /** Add a log message with all the supplied parameters along with method name */ + public actual fun entry(vararg argArray: Any?) + + /** Add log message indicating exit of a method */ + public actual fun exit() + + /** Add a log message with the return value of a method */ + public actual fun exit(result: T): T where T : Any? + + /** Add a log message indicating an exception will be thrown along with the stack trace. */ + public actual fun throwing(throwable: T): T where T : Throwable + + /** Add a log message indicating an exception is caught along with the stack trace. */ + public actual fun catching(throwable: T) where T : Throwable + + /** + * Returns whether this Logger is enabled for a given [Level]. + * + * @param level + * @return true if enabled, false otherwise. + */ + public fun isEnabledForLevel(level: io.github.oshai.Level): Boolean { + return when (level.toInt()) { + io.github.oshai.Levels.TRACE_INT -> isTraceEnabled + io.github.oshai.Levels.DEBUG_INT -> isDebugEnabled + io.github.oshai.Levels.INFO_INT -> isInfoEnabled + io.github.oshai.Levels.WARN_INT -> isWarnEnabled + io.github.oshai.Levels.ERROR_INT -> isErrorEnabled + else -> throw IllegalArgumentException("Level [$level] not recognized.") + } + } + + /** + * Is the logger instance enabled for the TRACE level? + * + * @return True if this Logger is enabled for the TRACE level, false otherwise. + * @since 1.4 + */ + public val isTraceEnabled: Boolean + + /** + * Log a message at the TRACE level. + * + * @param msg the message string to be logged + * @since 1.4 + */ + public fun trace(msg: String?) + + /** + * Log a message at the TRACE level according to the specified format and argument. + * + * This form avoids superfluous object creation when the logger is disabled for the TRACE level. + * + * @param format the format string + * @param arg the argument + * @since 1.4 + */ + public fun trace(format: String?, arg: Any?) + + /** + * Log a message at the TRACE level according to the specified format and arguments. + * + * This form avoids superfluous object creation when the logger is disabled for the TRACE level. + * + * @param format the format string + * @param arg1 the first argument + * @param arg2 the second argument + * @since 1.4 + */ + public fun trace(format: String?, arg1: Any?, arg2: Any?) + + /** + * Log a message at the TRACE level according to the specified format and arguments. + * + * This form avoids superfluous string concatenation when the logger is disabled for the TRACE + * level. However, this variant incurs the hidden (and relatively small) cost of creating an + * `Object[]` before invoking the method, even if this logger is disabled for TRACE. The variants + * taking [one][.trace] and [two][.trace] arguments exist solely in order to avoid this hidden + * cost. + * + * @param format the format string + * @param arguments a list of 3 or more arguments + * @since 1.4 + */ + public fun trace(format: String?, vararg arguments: Any?) + + /** + * Log an exception (throwable) at the TRACE level with an accompanying message. + * + * @param msg the message accompanying the exception + * @param t the exception (throwable) to log + * @since 1.4 + */ + public fun trace(msg: String?, t: Throwable?) + + /** + * Similar to [.isTraceEnabled] method except that the marker data is also taken into account. + * + * @param marker The marker data to take into consideration + * @return True if this Logger is enabled for the TRACE level, false otherwise. + * + * @since 1.4 + */ + public fun isTraceEnabled(marker: io.github.oshai.Marker?): Boolean + + /** + * Log a message with the specific Marker at the TRACE level. + * + * @param marker the marker data specific to this log statement + * @param msg the message string to be logged + * @since 1.4 + */ + public fun trace(marker: io.github.oshai.Marker?, msg: String?) + + /** + * This method is similar to [.trace] method except that the marker data is also taken into + * consideration. + * + * @param marker the marker data specific to this log statement + * @param format the format string + * @param arg the argument + * @since 1.4 + */ + public fun trace(marker: io.github.oshai.Marker?, format: String?, arg: Any?) + + /** + * This method is similar to [.trace] method except that the marker data is also taken into + * consideration. + * + * @param marker the marker data specific to this log statement + * @param format the format string + * @param arg1 the first argument + * @param arg2 the second argument + * @since 1.4 + */ + public fun trace(marker: io.github.oshai.Marker?, format: String?, arg1: Any?, arg2: Any?) + + /** + * This method is similar to [.trace] method except that the marker data is also taken into + * consideration. + * + * @param marker the marker data specific to this log statement + * @param format the format string + * @param argArray an array of arguments + * @since 1.4 + */ + public fun trace(marker: io.github.oshai.Marker?, format: String?, vararg argArray: Any?) + + /** + * This method is similar to [.trace] method except that the marker data is also taken into + * consideration. + * + * @param marker the marker data specific to this log statement + * @param msg the message accompanying the exception + * @param t the exception (throwable) to log + * @since 1.4 + */ + public fun trace(marker: io.github.oshai.Marker?, msg: String?, t: Throwable?) + + /** + * Is the logger instance enabled for the DEBUG level? + * + * @return True if this Logger is enabled for the DEBUG level, false otherwise. + */ + public val isDebugEnabled: Boolean + + /** + * Log a message at the DEBUG level. + * + * @param msg the message string to be logged + */ + public fun debug(msg: String?) + + /** + * Log a message at the DEBUG level according to the specified format and argument. + * + * This form avoids superfluous object creation when the logger is disabled for the DEBUG level. + * + * @param format the format string + * @param arg the argument + */ + public fun debug(format: String?, arg: Any?) + + /** + * Log a message at the DEBUG level according to the specified format and arguments. + * + * This form avoids superfluous object creation when the logger is disabled for the DEBUG level. + * + * @param format the format string + * @param arg1 the first argument + * @param arg2 the second argument + */ + public fun debug(format: String?, arg1: Any?, arg2: Any?) + + /** + * Log a message at the DEBUG level according to the specified format and arguments. + * + * This form avoids superfluous string concatenation when the logger is disabled for the DEBUG + * level. However, this variant incurs the hidden (and relatively small) cost of creating an + * `Object[]` before invoking the method, even if this logger is disabled for DEBUG. The variants + * taking [one][.debug] and [two][.debug] arguments exist solely in order to avoid this hidden + * cost. + * + * @param format the format string + * @param arguments a list of 3 or more arguments + */ + public fun debug(format: String?, vararg arguments: Any?) + + /** + * Log an exception (throwable) at the DEBUG level with an accompanying message. + * + * @param msg the message accompanying the exception + * @param t the exception (throwable) to log + */ + public fun debug(msg: String?, t: Throwable?) + + /** + * Similar to [.isDebugEnabled] method except that the marker data is also taken into account. + * + * @param marker The marker data to take into consideration + * @return True if this Logger is enabled for the DEBUG level, false otherwise. + */ + public fun isDebugEnabled(marker: io.github.oshai.Marker?): Boolean + + /** + * Log a message with the specific Marker at the DEBUG level. + * + * @param marker the marker data specific to this log statement + * @param msg the message string to be logged + */ + public fun debug(marker: io.github.oshai.Marker?, msg: String?) + + /** + * This method is similar to [.debug] method except that the marker data is also taken into + * consideration. + * + * @param marker the marker data specific to this log statement + * @param format the format string + * @param arg the argument + */ + public fun debug(marker: io.github.oshai.Marker?, format: String?, arg: Any?) + + /** + * This method is similar to [.debug] method except that the marker data is also taken into + * consideration. + * + * @param marker the marker data specific to this log statement + * @param format the format string + * @param arg1 the first argument + * @param arg2 the second argument + */ + public fun debug(marker: io.github.oshai.Marker?, format: String?, arg1: Any?, arg2: Any?) + + /** + * This method is similar to [.debug] method except that the marker data is also taken into + * consideration. + * + * @param marker the marker data specific to this log statement + * @param format the format string + * @param arguments a list of 3 or more arguments + */ + public fun debug(marker: io.github.oshai.Marker?, format: String?, vararg arguments: Any?) + + /** + * This method is similar to [.debug] method except that the marker data is also taken into + * consideration. + * + * @param marker the marker data specific to this log statement + * @param msg the message accompanying the exception + * @param t the exception (throwable) to log + */ + public fun debug(marker: io.github.oshai.Marker?, msg: String?, t: Throwable?) + + /** + * Is the logger instance enabled for the INFO level? + * + * @return True if this Logger is enabled for the INFO level, false otherwise. + */ + public val isInfoEnabled: Boolean + + /** + * Log a message at the INFO level. + * + * @param msg the message string to be logged + */ + public fun info(msg: String?) + + /** + * Log a message at the INFO level according to the specified format and argument. + * + * This form avoids superfluous object creation when the logger is disabled for the INFO level. + * + * @param format the format string + * @param arg the argument + */ + public fun info(format: String?, arg: Any?) + + /** + * Log a message at the INFO level according to the specified format and arguments. + * + * This form avoids superfluous object creation when the logger is disabled for the INFO level. + * + * @param format the format string + * @param arg1 the first argument + * @param arg2 the second argument + */ + public fun info(format: String?, arg1: Any?, arg2: Any?) + + /** + * Log a message at the INFO level according to the specified format and arguments. + * + * This form avoids superfluous string concatenation when the logger is disabled for the INFO + * level. However, this variant incurs the hidden (and relatively small) cost of creating an + * `Object[]` before invoking the method, even if this logger is disabled for INFO. The variants + * taking [one][.info] and [two][.info] arguments exist solely in order to avoid this hidden cost. + * + * @param format the format string + * @param arguments a list of 3 or more arguments + */ + public fun info(format: String?, vararg arguments: Any?) + + /** + * Log an exception (throwable) at the INFO level with an accompanying message. + * + * @param msg the message accompanying the exception + * @param t the exception (throwable) to log + */ + public fun info(msg: String?, t: Throwable?) + + /** + * Similar to [.isInfoEnabled] method except that the marker data is also taken into + * consideration. + * + * @param marker The marker data to take into consideration + * @return true if this Logger is enabled for the INFO level, false otherwise. + */ + public fun isInfoEnabled(marker: io.github.oshai.Marker?): Boolean + + /** + * Log a message with the specific Marker at the INFO level. + * + * @param marker The marker specific to this log statement + * @param msg the message string to be logged + */ + public fun info(marker: io.github.oshai.Marker?, msg: String?) + + /** + * This method is similar to [.info] method except that the marker data is also taken into + * consideration. + * + * @param marker the marker data specific to this log statement + * @param format the format string + * @param arg the argument + */ + public fun info(marker: io.github.oshai.Marker?, format: String?, arg: Any?) + + /** + * This method is similar to [.info] method except that the marker data is also taken into + * consideration. + * + * @param marker the marker data specific to this log statement + * @param format the format string + * @param arg1 the first argument + * @param arg2 the second argument + */ + public fun info(marker: io.github.oshai.Marker?, format: String?, arg1: Any?, arg2: Any?) + + /** + * This method is similar to [.info] method except that the marker data is also taken into + * consideration. + * + * @param marker the marker data specific to this log statement + * @param format the format string + * @param arguments a list of 3 or more arguments + */ + public fun info(marker: io.github.oshai.Marker?, format: String?, vararg arguments: Any?) + + /** + * This method is similar to [.info] method except that the marker data is also taken into + * consideration. + * + * @param marker the marker data for this log statement + * @param msg the message accompanying the exception + * @param t the exception (throwable) to log + */ + public fun info(marker: io.github.oshai.Marker?, msg: String?, t: Throwable?) + + /** + * Is the logger instance enabled for the WARN level? + * + * @return True if this Logger is enabled for the WARN level, false otherwise. + */ + public val isWarnEnabled: Boolean + + /** + * Log a message at the WARN level. + * + * @param msg the message string to be logged + */ + public fun warn(msg: String?) + + /** + * Log a message at the WARN level according to the specified format and argument. + * + * This form avoids superfluous object creation when the logger is disabled for the WARN level. + * + * @param format the format string + * @param arg the argument + */ + public fun warn(format: String?, arg: Any?) + + /** + * Log a message at the WARN level according to the specified format and arguments. + * + * This form avoids superfluous string concatenation when the logger is disabled for the WARN + * level. However, this variant incurs the hidden (and relatively small) cost of creating an + * `Object[]` before invoking the method, even if this logger is disabled for WARN. The variants + * taking [one][.warn] and [two][.warn] arguments exist solely in order to avoid this hidden cost. + * + * @param format the format string + * @param arguments a list of 3 or more arguments + */ + public fun warn(format: String?, vararg arguments: Any?) + + /** + * Log a message at the WARN level according to the specified format and arguments. + * + * This form avoids superfluous object creation when the logger is disabled for the WARN level. + * + * @param format the format string + * @param arg1 the first argument + * @param arg2 the second argument + */ + public fun warn(format: String?, arg1: Any?, arg2: Any?) + + /** + * Log an exception (throwable) at the WARN level with an accompanying message. + * + * @param msg the message accompanying the exception + * @param t the exception (throwable) to log + */ + public fun warn(msg: String?, t: Throwable?) + + /** + * Similar to [.isWarnEnabled] method except that the marker data is also taken into + * consideration. + * + * @param marker The marker data to take into consideration + * @return True if this Logger is enabled for the WARN level, false otherwise. + */ + public fun isWarnEnabled(marker: io.github.oshai.Marker?): Boolean + + /** + * Log a message with the specific Marker at the WARN level. + * + * @param marker The marker specific to this log statement + * @param msg the message string to be logged + */ + public fun warn(marker: io.github.oshai.Marker?, msg: String?) + + /** + * This method is similar to [.warn] method except that the marker data is also taken into + * consideration. + * + * @param marker the marker data specific to this log statement + * @param format the format string + * @param arg the argument + */ + public fun warn(marker: io.github.oshai.Marker?, format: String?, arg: Any?) + + /** + * This method is similar to [.warn] method except that the marker data is also taken into + * consideration. + * + * @param marker the marker data specific to this log statement + * @param format the format string + * @param arg1 the first argument + * @param arg2 the second argument + */ + public fun warn(marker: io.github.oshai.Marker?, format: String?, arg1: Any?, arg2: Any?) + + /** + * This method is similar to [.warn] method except that the marker data is also taken into + * consideration. + * + * @param marker the marker data specific to this log statement + * @param format the format string + * @param arguments a list of 3 or more arguments + */ + public fun warn(marker: io.github.oshai.Marker?, format: String?, vararg arguments: Any?) + + /** + * This method is similar to [.warn] method except that the marker data is also taken into + * consideration. + * + * @param marker the marker data for this log statement + * @param msg the message accompanying the exception + * @param t the exception (throwable) to log + */ + public fun warn(marker: io.github.oshai.Marker?, msg: String?, t: Throwable?) + + /** + * Is the logger instance enabled for the ERROR level? + * + * @return True if this Logger is enabled for the ERROR level, false otherwise. + */ + public val isErrorEnabled: Boolean + + /** + * Log a message at the ERROR level. + * + * @param msg the message string to be logged + */ + public fun error(msg: String?) + + /** + * Log a message at the ERROR level according to the specified format and argument. + * + * This form avoids superfluous object creation when the logger is disabled for the ERROR level. + * + * @param format the format string + * @param arg the argument + */ + public fun error(format: String?, arg: Any?) + + /** + * Log a message at the ERROR level according to the specified format and arguments. + * + * This form avoids superfluous object creation when the logger is disabled for the ERROR level. + * + * @param format the format string + * @param arg1 the first argument + * @param arg2 the second argument + */ + public fun error(format: String?, arg1: Any?, arg2: Any?) + + /** + * Log a message at the ERROR level according to the specified format and arguments. + * + * This form avoids superfluous string concatenation when the logger is disabled for the ERROR + * level. However, this variant incurs the hidden (and relatively small) cost of creating an + * `Object[]` before invoking the method, even if this logger is disabled for ERROR. The variants + * taking [one][.error] and [two][.error] arguments exist solely in order to avoid this hidden + * cost. + * + * @param format the format string + * @param arguments a list of 3 or more arguments + */ + public fun error(format: String?, vararg arguments: Any?) + + /** + * Log an exception (throwable) at the ERROR level with an accompanying message. + * + * @param msg the message accompanying the exception + * @param t the exception (throwable) to log + */ + public fun error(msg: String?, t: Throwable?) + + /** + * Similar to [.isErrorEnabled] method except that the marker data is also taken into + * consideration. + * + * @param marker The marker data to take into consideration + * @return True if this Logger is enabled for the ERROR level, false otherwise. + */ + public fun isErrorEnabled(marker: io.github.oshai.Marker?): Boolean + + /** + * Log a message with the specific Marker at the ERROR level. + * + * @param marker The marker specific to this log statement + * @param msg the message string to be logged + */ + public fun error(marker: io.github.oshai.Marker?, msg: String?) + + /** + * This method is similar to [.error] method except that the marker data is also taken into + * consideration. + * + * @param marker the marker data specific to this log statement + * @param format the format string + * @param arg the argument + */ + public fun error(marker: io.github.oshai.Marker?, format: String?, arg: Any?) + + /** + * This method is similar to [.error] method except that the marker data is also taken into + * consideration. + * + * @param marker the marker data specific to this log statement + * @param format the format string + * @param arg1 the first argument + * @param arg2 the second argument + */ + public fun error(marker: io.github.oshai.Marker?, format: String?, arg1: Any?, arg2: Any?) + + /** + * This method is similar to [.error] method except that the marker data is also taken into + * consideration. + * + * @param marker the marker data specific to this log statement + * @param format the format string + * @param arguments a list of 3 or more arguments + */ + public fun error(marker: io.github.oshai.Marker?, format: String?, vararg arguments: Any?) + + /** + * This method is similar to [.error] method except that the marker data is also taken into + * consideration. + * + * @param marker the marker data specific to this log statement + * @param msg the message accompanying the exception + * @param t the exception (throwable) to log + */ + public fun error(marker: io.github.oshai.Marker?, msg: String?, t: Throwable?) +} diff --git a/src/jvmMain/kotlin/mu/KLogging.kt b/src/jvmMain/kotlin/io/github/oshai/KLogging.kt similarity index 62% rename from src/jvmMain/kotlin/mu/KLogging.kt rename to src/jvmMain/kotlin/io/github/oshai/KLogging.kt index 6d0b4ab0..536f3184 100644 --- a/src/jvmMain/kotlin/mu/KLogging.kt +++ b/src/jvmMain/kotlin/io/github/oshai/KLogging.kt @@ -1,6 +1,6 @@ -package mu +package io.github.oshai -import mu.internal.KLoggerFactory +import io.github.oshai.internal.KLoggerFactory /** * A class with logging capabilities usage example: @@ -14,12 +14,12 @@ import mu.internal.KLoggerFactory * ``` */ public open class KLogging : KLoggable { - override val logger: KLogger = logger() + override val logger: io.github.oshai.KLogger = logger() } /** A class with logging capabilities and explicit logger name */ public open class NamedKLogging(name: String) : KLoggable { - override val logger: KLogger = logger(name) + override val logger: io.github.oshai.KLogger = logger(name) } /** @@ -29,11 +29,11 @@ public open class NamedKLogging(name: String) : KLoggable { public interface KLoggable { /** The member that performs the actual logging */ - public val logger: KLogger + public val logger: io.github.oshai.KLogger /** get logger for the class */ - public fun logger(): KLogger = KLoggerFactory.logger(this) + public fun logger(): io.github.oshai.KLogger = KLoggerFactory.logger(this) /** get logger by explicit name */ - public fun logger(name: String): KLogger = KLoggerFactory.logger(name) + public fun logger(name: String): io.github.oshai.KLogger = KLoggerFactory.logger(name) } diff --git a/src/jvmMain/kotlin/mu/KotlinLogging.kt b/src/jvmMain/kotlin/io/github/oshai/KotlinLogging.kt similarity index 58% rename from src/jvmMain/kotlin/mu/KotlinLogging.kt rename to src/jvmMain/kotlin/io/github/oshai/KotlinLogging.kt index 3aa32f34..5dce939b 100644 --- a/src/jvmMain/kotlin/mu/KotlinLogging.kt +++ b/src/jvmMain/kotlin/io/github/oshai/KotlinLogging.kt @@ -1,7 +1,6 @@ -package mu +package io.github.oshai -import mu.internal.KLoggerFactory -import org.slf4j.Logger +import io.github.oshai.internal.KLoggerFactory public actual object KotlinLogging { /** @@ -13,9 +12,4 @@ public actual object KotlinLogging { public actual fun logger(func: () -> Unit): KLogger = KLoggerFactory.logger(func) public actual fun logger(name: String): KLogger = KLoggerFactory.logger(name) - - public fun logger(underlyingLogger: Logger): KLogger = - KLoggerFactory.wrapJLogger(underlyingLogger) } - -public fun Logger.toKLogger(): KLogger = KotlinLogging.logger(this) diff --git a/src/jvmMain/kotlin/mu/KotlinLoggingMDC.kt b/src/jvmMain/kotlin/io/github/oshai/KotlinLoggingMDC.kt similarity index 98% rename from src/jvmMain/kotlin/mu/KotlinLoggingMDC.kt rename to src/jvmMain/kotlin/io/github/oshai/KotlinLoggingMDC.kt index 695ba843..2781f2b2 100644 --- a/src/jvmMain/kotlin/mu/KotlinLoggingMDC.kt +++ b/src/jvmMain/kotlin/io/github/oshai/KotlinLoggingMDC.kt @@ -1,4 +1,4 @@ -package mu +package io.github.oshai import org.slf4j.MDC diff --git a/src/jvmMain/kotlin/mu/internal/ErrorMessageProducer.kt b/src/jvmMain/kotlin/io/github/oshai/internal/ErrorMessageProducer.kt similarity index 89% rename from src/jvmMain/kotlin/mu/internal/ErrorMessageProducer.kt rename to src/jvmMain/kotlin/io/github/oshai/internal/ErrorMessageProducer.kt index 4cf1aa51..c79f3d4c 100644 --- a/src/jvmMain/kotlin/mu/internal/ErrorMessageProducer.kt +++ b/src/jvmMain/kotlin/io/github/oshai/internal/ErrorMessageProducer.kt @@ -1,4 +1,4 @@ -package mu.internal +package io.github.oshai.internal public actual object ErrorMessageProducer { public actual fun getErrorLog(e: Exception): String { diff --git a/src/jvmMain/kotlin/io/github/oshai/internal/KLoggerFactory.kt b/src/jvmMain/kotlin/io/github/oshai/internal/KLoggerFactory.kt new file mode 100644 index 00000000..cdd22ca4 --- /dev/null +++ b/src/jvmMain/kotlin/io/github/oshai/internal/KLoggerFactory.kt @@ -0,0 +1,28 @@ +package io.github.oshai.internal + +import io.github.oshai.KLoggable +import io.github.oshai.KLogger +import io.github.oshai.jul.internal.JulLoggerFactory +import io.github.oshai.slf4j.internal.Slf4jLoggerFactory + +/** factory methods to obtain a [Logger] */ +@Suppress("NOTHING_TO_INLINE") +internal object KLoggerFactory { + + /** get logger for the class */ + internal inline fun logger(loggable: KLoggable): KLogger = + logger(KLoggerNameResolver.name(loggable.javaClass)) + + /** get logger by explicit name */ + internal inline fun logger(name: String): KLogger { + if (System.getProperty("kotlin-logging-to-jul") != null) { + return JulLoggerFactory.wrapJLogger(JulLoggerFactory.jLogger(name)) + } + // default to slf4j + return Slf4jLoggerFactory.wrapJLogger(Slf4jLoggerFactory.jLogger(name)) + } + + /** get logger for the method, assuming it was declared at the logger file/class */ + internal inline fun logger(noinline func: () -> Unit): KLogger = + logger(KLoggerNameResolver.name(func)) +} diff --git a/src/jvmMain/kotlin/mu/internal/KLoggerNameResolver.kt b/src/jvmMain/kotlin/io/github/oshai/internal/KLoggerNameResolver.kt similarity index 97% rename from src/jvmMain/kotlin/mu/internal/KLoggerNameResolver.kt rename to src/jvmMain/kotlin/io/github/oshai/internal/KLoggerNameResolver.kt index 34a8935b..149eeaf4 100644 --- a/src/jvmMain/kotlin/mu/internal/KLoggerNameResolver.kt +++ b/src/jvmMain/kotlin/io/github/oshai/internal/KLoggerNameResolver.kt @@ -1,4 +1,4 @@ -package mu.internal +package io.github.oshai.internal import java.lang.reflect.Modifier diff --git a/src/jvmMain/kotlin/io/github/oshai/jul/JulExtensions.kt b/src/jvmMain/kotlin/io/github/oshai/jul/JulExtensions.kt new file mode 100644 index 00000000..8353c052 --- /dev/null +++ b/src/jvmMain/kotlin/io/github/oshai/jul/JulExtensions.kt @@ -0,0 +1 @@ +package io.github.oshai.jul diff --git a/src/jvmMain/kotlin/io/github/oshai/jul/internal/JulLoggerFactory.kt b/src/jvmMain/kotlin/io/github/oshai/jul/internal/JulLoggerFactory.kt new file mode 100644 index 00000000..92429452 --- /dev/null +++ b/src/jvmMain/kotlin/io/github/oshai/jul/internal/JulLoggerFactory.kt @@ -0,0 +1,13 @@ +package io.github.oshai.jul.internal + +import io.github.oshai.KLogger +import java.util.logging.Logger + +internal object JulLoggerFactory { + + /** get a java logger by name */ + fun jLogger(name: String): Logger = Logger.getLogger(name) + + /** wrap java logger based on location awareness */ + fun wrapJLogger(jLogger: Logger): KLogger = JulLoggerWrapper(jLogger) +} diff --git a/src/jvmMain/kotlin/io/github/oshai/jul/internal/JulLoggerWrapper.kt b/src/jvmMain/kotlin/io/github/oshai/jul/internal/JulLoggerWrapper.kt new file mode 100644 index 00000000..f049f15a --- /dev/null +++ b/src/jvmMain/kotlin/io/github/oshai/jul/internal/JulLoggerWrapper.kt @@ -0,0 +1,392 @@ +package io.github.oshai.jul.internal + +import io.github.oshai.KLogger +import io.github.oshai.Marker +import io.github.oshai.internal.toStringSafe +import java.util.logging.Level +import java.util.logging.Logger + +@Suppress("OVERRIDE_BY_INLINE", "NOTHING_TO_INLINE") +internal class JulLoggerWrapper(override val underlyingLogger: Logger) : KLogger { + override val name: String + get() = underlyingLogger.name + + /** Lazy add a log message if isTraceEnabled is true */ + override fun trace(msg: () -> Any?) { + if (isTraceEnabled) trace(msg.toStringSafe()) + } + + /** Lazy add a log message if isDebugEnabled is true */ + override fun debug(msg: () -> Any?) { + if (isDebugEnabled) debug(msg.toStringSafe()) + } + + /** Lazy add a log message if isInfoEnabled is true */ + override fun info(msg: () -> Any?) { + if (isInfoEnabled) info(msg.toStringSafe()) + } + + /** Lazy add a log message if isWarnEnabled is true */ + override fun warn(msg: () -> Any?) { + if (isWarnEnabled) warn(msg.toStringSafe()) + } + + /** Lazy add a log message if isErrorEnabled is true */ + override fun error(msg: () -> Any?) { + if (isErrorEnabled) error(msg.toStringSafe()) + } + + /** Lazy add a log message with throwable payload if isTraceEnabled is true */ + override fun trace(t: Throwable?, msg: () -> Any?) { + if (isTraceEnabled) trace(msg.toStringSafe(), t) + } + + /** Lazy add a log message with throwable payload if isDebugEnabled is true */ + override fun debug(t: Throwable?, msg: () -> Any?) { + if (isDebugEnabled) debug(msg.toStringSafe(), t) + } + + /** Lazy add a log message with throwable payload if isInfoEnabled is true */ + override fun info(t: Throwable?, msg: () -> Any?) { + if (isInfoEnabled) info(msg.toStringSafe(), t) + } + + /** Lazy add a log message with throwable payload if isWarnEnabled is true */ + override fun warn(t: Throwable?, msg: () -> Any?) { + if (isWarnEnabled) warn(msg.toStringSafe(), t) + } + + /** Lazy add a log message with throwable payload if isErrorEnabled is true */ + override fun error(t: Throwable?, msg: () -> Any?) { + if (isErrorEnabled) error(msg.toStringSafe(), t) + } + + /** Lazy add a log message with a marker if isTraceEnabled is true */ + override fun trace(marker: Marker?, msg: () -> Any?) { + if (isTraceEnabled) trace(marker, msg.toStringSafe()) + } + + /** Lazy add a log message with a marker if isDebugEnabled is true */ + override fun debug(marker: Marker?, msg: () -> Any?) { + if (isDebugEnabled) debug(marker, msg.toStringSafe()) + } + + /** Lazy add a log message with a marker if isInfoEnabled is true */ + override fun info(marker: Marker?, msg: () -> Any?) { + if (isInfoEnabled) info(marker, msg.toStringSafe()) + } + + /** Lazy add a log message with a marker if isWarnEnabled is true */ + override fun warn(marker: Marker?, msg: () -> Any?) { + if (isWarnEnabled) warn(marker, msg.toStringSafe()) + } + + /** Lazy add a log message with a marker if isErrorEnabled is true */ + override fun error(marker: Marker?, msg: () -> Any?) { + if (isErrorEnabled) error(marker, msg.toStringSafe()) + } + + /** Lazy add a log message with a marker and throwable payload if isTraceEnabled is true */ + override fun trace(marker: Marker?, t: Throwable?, msg: () -> Any?) { + if (isTraceEnabled) trace(marker, msg.toStringSafe(), t) + } + + override fun trace(msg: String?) { + if (isTraceEnabled) { + underlyingLogger.log(io.github.oshai.Level.TRACE.toJULLevel(), msg) + } + } + + override fun trace(format: String?, arg: Any?) { + underlyingLogger.log(io.github.oshai.Level.TRACE.toJULLevel(), format, arg) + } + + override fun trace(format: String?, arg1: Any?, arg2: Any?) { + underlyingLogger.log(io.github.oshai.Level.TRACE.toJULLevel(), format, arrayOf(arg1, arg2)) + } + + override fun trace(format: String?, vararg arguments: Any?) { + underlyingLogger.log(io.github.oshai.Level.TRACE.toJULLevel(), format, arguments) + } + + override fun trace(msg: String?, t: Throwable?) { + underlyingLogger.log(io.github.oshai.Level.TRACE.toJULLevel(), msg, t) + } + + override fun trace(marker: Marker?, msg: String?) { + underlyingLogger.log(io.github.oshai.Level.TRACE.toJULLevel(), msg) + } + + override fun trace(marker: Marker?, format: String?, arg: Any?) { + underlyingLogger.log(io.github.oshai.Level.TRACE.toJULLevel(), format, arg) + } + + override fun trace(marker: Marker?, format: String?, arg1: Any?, arg2: Any?) { + underlyingLogger.log(io.github.oshai.Level.TRACE.toJULLevel(), format, arrayOf(arg1, arg2)) + } + + override fun trace(marker: Marker?, format: String?, vararg argArray: Any?) { + underlyingLogger.log(io.github.oshai.Level.TRACE.toJULLevel(), format, argArray) + } + + override fun trace(marker: Marker?, msg: String?, t: Throwable?) { + underlyingLogger.log(io.github.oshai.Level.TRACE.toJULLevel(), msg, t) + } + + /** Lazy add a log message with a marker and throwable payload if isDebugEnabled is true */ + override fun debug(marker: Marker?, t: Throwable?, msg: () -> Any?) { + if (isDebugEnabled) debug(marker, msg.toStringSafe(), t) + } + + override fun debug(msg: String?) { + if (isTraceEnabled) { + underlyingLogger.log(io.github.oshai.Level.DEBUG.toJULLevel(), msg) + } + } + + override fun debug(format: String?, arg: Any?) { + underlyingLogger.log(io.github.oshai.Level.DEBUG.toJULLevel(), format, arg) + } + + override fun debug(format: String?, arg1: Any?, arg2: Any?) { + underlyingLogger.log(io.github.oshai.Level.DEBUG.toJULLevel(), format, arrayOf(arg1, arg2)) + } + + override fun debug(format: String?, vararg arguments: Any?) { + underlyingLogger.log(io.github.oshai.Level.DEBUG.toJULLevel(), format, arguments) + } + + override fun debug(msg: String?, t: Throwable?) { + underlyingLogger.log(io.github.oshai.Level.DEBUG.toJULLevel(), msg, t) + } + + override fun debug(marker: Marker?, msg: String?) { + underlyingLogger.log(io.github.oshai.Level.DEBUG.toJULLevel(), msg) + } + + override fun debug(marker: Marker?, format: String?, arg: Any?) { + underlyingLogger.log(io.github.oshai.Level.DEBUG.toJULLevel(), format, arg) + } + + override fun debug(marker: Marker?, format: String?, arg1: Any?, arg2: Any?) { + underlyingLogger.log(io.github.oshai.Level.DEBUG.toJULLevel(), format, arrayOf(arg1, arg2)) + } + + override fun debug(marker: Marker?, format: String?, vararg argArray: Any?) { + underlyingLogger.log(io.github.oshai.Level.DEBUG.toJULLevel(), format, argArray) + } + + override fun debug(marker: Marker?, msg: String?, t: Throwable?) { + underlyingLogger.log(io.github.oshai.Level.DEBUG.toJULLevel(), msg, t) + } + + /** Lazy add a log message with a marker and throwable payload if isInfoEnabled is true */ + override fun info(marker: Marker?, t: Throwable?, msg: () -> Any?) { + if (isInfoEnabled) info(marker, msg.toStringSafe(), t) + } + + override fun info(msg: String?) { + if (isTraceEnabled) { + underlyingLogger.info(msg) + } + } + + override fun info(format: String?, arg: Any?) { + underlyingLogger.log(io.github.oshai.Level.INFO.toJULLevel(), format, arg) + } + + override fun info(format: String?, arg1: Any?, arg2: Any?) { + underlyingLogger.log(io.github.oshai.Level.INFO.toJULLevel(), format, arrayOf(arg1, arg2)) + } + + override fun info(format: String?, vararg arguments: Any?) { + underlyingLogger.log(io.github.oshai.Level.INFO.toJULLevel(), format, arguments) + } + + override fun info(msg: String?, t: Throwable?) { + underlyingLogger.log(io.github.oshai.Level.INFO.toJULLevel(), msg, t) + } + + override fun info(marker: Marker?, msg: String?) { + underlyingLogger.log(io.github.oshai.Level.INFO.toJULLevel(), msg) + } + + override fun info(marker: Marker?, format: String?, arg: Any?) { + underlyingLogger.log(io.github.oshai.Level.INFO.toJULLevel(), format, arg) + } + + override fun info(marker: Marker?, format: String?, arg1: Any?, arg2: Any?) { + underlyingLogger.log(io.github.oshai.Level.INFO.toJULLevel(), format, arrayOf(arg1, arg2)) + } + + override fun info(marker: Marker?, format: String?, vararg argArray: Any?) { + underlyingLogger.log(io.github.oshai.Level.INFO.toJULLevel(), format, argArray) + } + + override fun info(marker: Marker?, msg: String?, t: Throwable?) { + underlyingLogger.log(io.github.oshai.Level.INFO.toJULLevel(), msg, t) + } + + /** Lazy add a log message with a marker and throwable payload if isWarnEnabled is true */ + override fun warn(marker: Marker?, t: Throwable?, msg: () -> Any?) { + if (isWarnEnabled) warn(marker, msg.toStringSafe(), t) + } + + override fun warn(msg: String?) { + if (isTraceEnabled) { + underlyingLogger.log(io.github.oshai.Level.WARN.toJULLevel(), msg) + } + } + + override fun warn(format: String?, arg: Any?) { + underlyingLogger.log(io.github.oshai.Level.WARN.toJULLevel(), format, arg) + } + + override fun warn(format: String?, arg1: Any?, arg2: Any?) { + underlyingLogger.log(io.github.oshai.Level.WARN.toJULLevel(), format, arrayOf(arg1, arg2)) + } + + override fun warn(format: String?, vararg arguments: Any?) { + underlyingLogger.log(io.github.oshai.Level.WARN.toJULLevel(), format, arguments) + } + + override fun warn(msg: String?, t: Throwable?) { + underlyingLogger.log(io.github.oshai.Level.WARN.toJULLevel(), msg, t) + } + + override fun warn(marker: Marker?, msg: String?) { + underlyingLogger.log(io.github.oshai.Level.WARN.toJULLevel(), msg) + } + + override fun warn(marker: Marker?, format: String?, arg: Any?) { + underlyingLogger.log(io.github.oshai.Level.WARN.toJULLevel(), format, arg) + } + + override fun warn(marker: Marker?, format: String?, arg1: Any?, arg2: Any?) { + underlyingLogger.log(io.github.oshai.Level.WARN.toJULLevel(), format, arrayOf(arg1, arg2)) + } + + override fun warn(marker: Marker?, format: String?, vararg argArray: Any?) { + underlyingLogger.log(io.github.oshai.Level.WARN.toJULLevel(), format, argArray) + } + + override fun warn(marker: Marker?, msg: String?, t: Throwable?) { + underlyingLogger.log(io.github.oshai.Level.WARN.toJULLevel(), msg, t) + } + + /** Lazy add a log message with a marker and throwable payload if isErrorEnabled is true */ + override fun error(marker: Marker?, t: Throwable?, msg: () -> Any?) { + if (isErrorEnabled) error(marker, msg.toStringSafe(), t) + } + + override fun error(msg: String?) { + if (isTraceEnabled) { + underlyingLogger.log(io.github.oshai.Level.ERROR.toJULLevel(), msg) + } + } + + override fun error(format: String?, arg: Any?) { + underlyingLogger.log(io.github.oshai.Level.ERROR.toJULLevel(), format, arg) + } + + override fun error(format: String?, arg1: Any?, arg2: Any?) { + underlyingLogger.log(io.github.oshai.Level.ERROR.toJULLevel(), format, arrayOf(arg1, arg2)) + } + + override fun error(format: String?, vararg arguments: Any?) { + underlyingLogger.log(io.github.oshai.Level.ERROR.toJULLevel(), format, arguments) + } + + override fun error(msg: String?, t: Throwable?) { + underlyingLogger.log(io.github.oshai.Level.ERROR.toJULLevel(), msg, t) + } + + override fun error(marker: Marker?, msg: String?) { + underlyingLogger.log(io.github.oshai.Level.ERROR.toJULLevel(), msg) + } + + override fun error(marker: Marker?, format: String?, arg: Any?) { + underlyingLogger.log(io.github.oshai.Level.ERROR.toJULLevel(), format, arg) + } + + override fun error(marker: Marker?, format: String?, arg1: Any?, arg2: Any?) { + underlyingLogger.log(io.github.oshai.Level.ERROR.toJULLevel(), format, arrayOf(arg1, arg2)) + } + + override fun error(marker: Marker?, format: String?, vararg argArray: Any?) { + underlyingLogger.log(io.github.oshai.Level.ERROR.toJULLevel(), format, argArray) + } + + override fun error(marker: Marker?, msg: String?, t: Throwable?) { + underlyingLogger.log(io.github.oshai.Level.ERROR.toJULLevel(), msg, t) + } + + override inline fun entry(vararg argArray: Any?) { + trace("entry({})", argArray) + } + + override inline fun exit() { + trace("exit") + } + + override inline fun exit(result: T): T { + trace("exit({})", result) + return result + } + + override inline fun throwing(throwable: T): T { + error("throwing($throwable)", throwable) + return throwable + } + + override inline fun catching(throwable: T) { + error("catching($throwable)", throwable) + } + + override val isTraceEnabled: Boolean + get() = underlyingLogger.isLoggable(io.github.oshai.Level.TRACE.toJULLevel()) + + override fun isTraceEnabled(marker: Marker?): Boolean { + return underlyingLogger.isLoggable(io.github.oshai.Level.TRACE.toJULLevel()) + } + + override val isDebugEnabled: Boolean + get() = underlyingLogger.isLoggable(io.github.oshai.Level.DEBUG.toJULLevel()) + + override fun isDebugEnabled(marker: Marker?): Boolean { + return underlyingLogger.isLoggable(io.github.oshai.Level.DEBUG.toJULLevel()) + } + + override val isInfoEnabled: Boolean + get() = underlyingLogger.isLoggable(io.github.oshai.Level.INFO.toJULLevel()) + + override fun isInfoEnabled(marker: Marker?): Boolean { + return underlyingLogger.isLoggable(io.github.oshai.Level.INFO.toJULLevel()) + } + + override val isWarnEnabled: Boolean + get() = underlyingLogger.isLoggable(io.github.oshai.Level.WARN.toJULLevel()) + + override fun isWarnEnabled(marker: Marker?): Boolean { + return underlyingLogger.isLoggable(io.github.oshai.Level.WARN.toJULLevel()) + } + + override val isErrorEnabled: Boolean + get() = underlyingLogger.isLoggable(io.github.oshai.Level.ERROR.toJULLevel()) + + override fun isErrorEnabled(marker: Marker?): Boolean { + return underlyingLogger.isLoggable(io.github.oshai.Level.ERROR.toJULLevel()) + } + + private fun io.github.oshai.Level.toJULLevel(): Level { + val julLevel: Level = + when (this) { + io.github.oshai.Level.TRACE -> Level.FINEST + io.github.oshai.Level.DEBUG -> Level.FINE + io.github.oshai.Level.INFO -> Level.INFO + io.github.oshai.Level.WARN -> Level.WARNING + io.github.oshai.Level.ERROR -> Level.SEVERE + } + return julLevel + } +} diff --git a/src/jvmMain/kotlin/io/github/oshai/slf4j/Slf4jExtensions.kt b/src/jvmMain/kotlin/io/github/oshai/slf4j/Slf4jExtensions.kt new file mode 100644 index 00000000..de45b03b --- /dev/null +++ b/src/jvmMain/kotlin/io/github/oshai/slf4j/Slf4jExtensions.kt @@ -0,0 +1,16 @@ +package io.github.oshai.slf4j + +import io.github.oshai.KLogger +import io.github.oshai.KotlinLogging +import io.github.oshai.Marker +import io.github.oshai.slf4j.internal.Slf4jLoggerFactory +import org.slf4j.Logger +import org.slf4j.MarkerFactory + +public fun Marker.toSlf4j(): org.slf4j.Marker = MarkerFactory.getMarker(this.getName()) + +@Suppress("UnusedReceiverParameter") +public fun KotlinLogging.logger(underlyingLogger: Logger): KLogger = + Slf4jLoggerFactory.wrapJLogger(underlyingLogger) + +public fun Logger.toKLogger(): KLogger = KotlinLogging.logger(this) diff --git a/src/jvmMain/kotlin/mu/internal/LocationAwareKLogger.kt b/src/jvmMain/kotlin/io/github/oshai/slf4j/internal/LocationAwareKLogger.kt similarity index 63% rename from src/jvmMain/kotlin/mu/internal/LocationAwareKLogger.kt rename to src/jvmMain/kotlin/io/github/oshai/slf4j/internal/LocationAwareKLogger.kt index 6280be6e..ec1e444a 100644 --- a/src/jvmMain/kotlin/mu/internal/LocationAwareKLogger.kt +++ b/src/jvmMain/kotlin/io/github/oshai/slf4j/internal/LocationAwareKLogger.kt @@ -1,9 +1,7 @@ -package mu.internal +package io.github.oshai.slf4j.internal -import mu.KLogger -import mu.KMarkerFactory -import org.slf4j.Logger -import org.slf4j.Marker +import io.github.oshai.internal.toStringSafe +import io.github.oshai.slf4j.toSlf4j import org.slf4j.helpers.MessageFormatter import org.slf4j.spi.LocationAwareLogger @@ -13,14 +11,16 @@ import org.slf4j.spi.LocationAwareLogger */ @Suppress("VariableNaming", "TooManyFunctions") internal class LocationAwareKLogger(override val underlyingLogger: LocationAwareLogger) : - KLogger, Logger by underlyingLogger { + Slf4jLoggerWrapper(underlyingLogger), io.github.oshai.KLogger + // , Logger by underlyingLogger +{ private val fqcn: String = LocationAwareKLogger::class.java.name - private val ENTRY = KMarkerFactory.getMarker("ENTRY") - private val EXIT = KMarkerFactory.getMarker("EXIT") + private val ENTRY = io.github.oshai.KMarkerFactory.getMarker("ENTRY").toSlf4j() + private val EXIT = io.github.oshai.KMarkerFactory.getMarker("EXIT").toSlf4j() - private val THROWING = KMarkerFactory.getMarker("THROWING") - private val CATCHING = KMarkerFactory.getMarker("CATCHING") + private val THROWING = io.github.oshai.KMarkerFactory.getMarker("THROWING").toSlf4j() + private val CATCHING = io.github.oshai.KMarkerFactory.getMarker("CATCHING").toSlf4j() private val EXITONLY = "exit" private val EXITMESSAGE = "exit with ({})" @@ -42,7 +42,7 @@ internal class LocationAwareKLogger(override val underlyingLogger: LocationAware underlyingLogger.log(null, fqcn, LocationAwareLogger.TRACE_INT, msg, arrayOf(arg1, arg2), null) } - override fun trace(msg: String?, argArray: Array) { + override fun trace(msg: String?, vararg argArray: Any?) { if (!underlyingLogger.isTraceEnabled) return underlyingLogger.log(null, fqcn, LocationAwareLogger.TRACE_INT, msg, argArray, null) @@ -54,33 +54,35 @@ internal class LocationAwareKLogger(override val underlyingLogger: LocationAware underlyingLogger.log(null, fqcn, LocationAwareLogger.TRACE_INT, msg, null, t) } - override fun trace(marker: Marker?, msg: String?) { + override fun trace(marker: io.github.oshai.Marker?, msg: String?) { if (!underlyingLogger.isTraceEnabled) return - underlyingLogger.log(marker, fqcn, LocationAwareLogger.TRACE_INT, msg, null, null) + underlyingLogger.log(marker?.toSlf4j(), fqcn, LocationAwareLogger.TRACE_INT, msg, null, null) } - override fun trace(marker: Marker?, msg: String?, arg: Any?) { + override fun trace(marker: io.github.oshai.Marker?, msg: String?, arg: Any?) { if (!underlyingLogger.isTraceEnabled) return - underlyingLogger.log(marker, fqcn, LocationAwareLogger.TRACE_INT, msg, arrayOf(arg), null) + underlyingLogger.log( + marker?.toSlf4j(), fqcn, LocationAwareLogger.TRACE_INT, msg, arrayOf(arg), null) } - override fun trace(marker: Marker?, msg: String?, arg1: Any?, arg2: Any?) { + override fun trace(marker: io.github.oshai.Marker?, msg: String?, arg1: Any?, arg2: Any?) { if (!underlyingLogger.isTraceEnabled) return underlyingLogger.log( - marker, fqcn, LocationAwareLogger.TRACE_INT, msg, arrayOf(arg1, arg2), null) + marker?.toSlf4j(), fqcn, LocationAwareLogger.TRACE_INT, msg, arrayOf(arg1, arg2), null) } - override fun trace(marker: Marker?, msg: String?, argArray: Array) { + override fun trace(marker: io.github.oshai.Marker?, msg: String?, vararg argArray: Any?) { if (!underlyingLogger.isTraceEnabled) return - underlyingLogger.log(marker, fqcn, LocationAwareLogger.TRACE_INT, msg, argArray, null) + underlyingLogger.log( + marker?.toSlf4j(), fqcn, LocationAwareLogger.TRACE_INT, msg, argArray, null) } - override fun trace(marker: Marker?, msg: String?, t: Throwable?) { + override fun trace(marker: io.github.oshai.Marker?, msg: String?, t: Throwable?) { if (!underlyingLogger.isTraceEnabled) return - underlyingLogger.log(marker, fqcn, LocationAwareLogger.TRACE_INT, msg, null, t) + underlyingLogger.log(marker?.toSlf4j(), fqcn, LocationAwareLogger.TRACE_INT, msg, null, t) } override fun debug(msg: String?) { @@ -101,7 +103,7 @@ internal class LocationAwareKLogger(override val underlyingLogger: LocationAware underlyingLogger.log(null, fqcn, LocationAwareLogger.DEBUG_INT, msg, arrayOf(arg1, arg2), null) } - override fun debug(msg: String?, argArray: Array) { + override fun debug(msg: String?, vararg argArray: Any?) { if (!underlyingLogger.isDebugEnabled) return underlyingLogger.log(null, fqcn, LocationAwareLogger.DEBUG_INT, msg, argArray, null) @@ -113,33 +115,35 @@ internal class LocationAwareKLogger(override val underlyingLogger: LocationAware underlyingLogger.log(null, fqcn, LocationAwareLogger.DEBUG_INT, msg, null, t) } - override fun debug(marker: Marker?, msg: String?) { + override fun debug(marker: io.github.oshai.Marker?, msg: String?) { if (!underlyingLogger.isDebugEnabled) return - underlyingLogger.log(marker, fqcn, LocationAwareLogger.DEBUG_INT, msg, null, null) + underlyingLogger.log(marker?.toSlf4j(), fqcn, LocationAwareLogger.DEBUG_INT, msg, null, null) } - override fun debug(marker: Marker?, msg: String?, arg: Any?) { + override fun debug(marker: io.github.oshai.Marker?, msg: String?, arg: Any?) { if (!underlyingLogger.isDebugEnabled) return - underlyingLogger.log(marker, fqcn, LocationAwareLogger.DEBUG_INT, msg, arrayOf(arg), null) + underlyingLogger.log( + marker?.toSlf4j(), fqcn, LocationAwareLogger.DEBUG_INT, msg, arrayOf(arg), null) } - override fun debug(marker: Marker?, arg: String?, arg1: Any?, arg2: Any?) { + override fun debug(marker: io.github.oshai.Marker?, arg: String?, arg1: Any?, arg2: Any?) { if (!underlyingLogger.isDebugEnabled) return underlyingLogger.log( - marker, fqcn, LocationAwareLogger.DEBUG_INT, arg, arrayOf(arg1, arg2), null) + marker?.toSlf4j(), fqcn, LocationAwareLogger.DEBUG_INT, arg, arrayOf(arg1, arg2), null) } - override fun debug(marker: Marker?, arg: String?, argArray: Array) { + override fun debug(marker: io.github.oshai.Marker?, arg: String?, vararg argArray: Any?) { if (!underlyingLogger.isDebugEnabled) return - underlyingLogger.log(marker, fqcn, LocationAwareLogger.DEBUG_INT, arg, argArray, null) + underlyingLogger.log( + marker?.toSlf4j(), fqcn, LocationAwareLogger.DEBUG_INT, arg, argArray, null) } - override fun debug(marker: Marker?, msg: String?, t: Throwable?) { + override fun debug(marker: io.github.oshai.Marker?, msg: String?, t: Throwable?) { if (!underlyingLogger.isDebugEnabled) return - underlyingLogger.log(marker, fqcn, LocationAwareLogger.DEBUG_INT, msg, null, t) + underlyingLogger.log(marker?.toSlf4j(), fqcn, LocationAwareLogger.DEBUG_INT, msg, null, t) } override fun info(msg: String?) { @@ -160,7 +164,7 @@ internal class LocationAwareKLogger(override val underlyingLogger: LocationAware underlyingLogger.log(null, fqcn, LocationAwareLogger.INFO_INT, msg, arrayOf(arg1, arg2), null) } - override fun info(msg: String?, argArray: Array) { + override fun info(msg: String?, vararg argArray: Any?) { if (!underlyingLogger.isInfoEnabled) return underlyingLogger.log(null, fqcn, LocationAwareLogger.INFO_INT, msg, argArray, null) @@ -172,29 +176,31 @@ internal class LocationAwareKLogger(override val underlyingLogger: LocationAware underlyingLogger.log(null, fqcn, LocationAwareLogger.INFO_INT, msg, null, t) } - override fun info(marker: Marker?, msg: String?) { + override fun info(marker: io.github.oshai.Marker?, msg: String?) { if (!underlyingLogger.isInfoEnabled) return - underlyingLogger.log(marker, fqcn, LocationAwareLogger.INFO_INT, msg, null, null) + underlyingLogger.log(marker?.toSlf4j(), fqcn, LocationAwareLogger.INFO_INT, msg, null, null) } - override fun info(marker: Marker?, msg: String?, arg: Any?) { + override fun info(marker: io.github.oshai.Marker?, msg: String?, arg: Any?) { if (!underlyingLogger.isInfoEnabled) return - underlyingLogger.log(marker, fqcn, LocationAwareLogger.INFO_INT, msg, arrayOf(arg), null) + underlyingLogger.log( + marker?.toSlf4j(), fqcn, LocationAwareLogger.INFO_INT, msg, arrayOf(arg), null) } - override fun info(marker: Marker?, msg: String?, arg1: Any?, arg2: Any?) { + override fun info(marker: io.github.oshai.Marker?, msg: String?, arg1: Any?, arg2: Any?) { if (!underlyingLogger.isInfoEnabled) return - underlyingLogger.log(marker, fqcn, LocationAwareLogger.INFO_INT, msg, arrayOf(arg1, arg2), null) + underlyingLogger.log( + marker?.toSlf4j(), fqcn, LocationAwareLogger.INFO_INT, msg, arrayOf(arg1, arg2), null) } - override fun info(marker: Marker?, msg: String?, argArray: Array) { + override fun info(marker: io.github.oshai.Marker?, msg: String?, vararg argArray: Any?) { if (!underlyingLogger.isInfoEnabled) return - underlyingLogger.log(marker, fqcn, LocationAwareLogger.INFO_INT, msg, argArray, null) + underlyingLogger.log(marker?.toSlf4j(), fqcn, LocationAwareLogger.INFO_INT, msg, argArray, null) } - override fun info(marker: Marker?, msg: String?, t: Throwable?) { + override fun info(marker: io.github.oshai.Marker?, msg: String?, t: Throwable?) { if (!underlyingLogger.isInfoEnabled) return - underlyingLogger.log(marker, fqcn, LocationAwareLogger.INFO_INT, msg, null, t) + underlyingLogger.log(marker?.toSlf4j(), fqcn, LocationAwareLogger.INFO_INT, msg, null, t) } override fun warn(msg: String?) { @@ -215,7 +221,7 @@ internal class LocationAwareKLogger(override val underlyingLogger: LocationAware underlyingLogger.log(null, fqcn, LocationAwareLogger.WARN_INT, msg, arrayOf(arg1, arg2), null) } - override fun warn(msg: String?, argArray: Array) { + override fun warn(msg: String?, vararg argArray: Any?) { if (!underlyingLogger.isWarnEnabled) return underlyingLogger.log(null, fqcn, LocationAwareLogger.WARN_INT, msg, argArray, null) @@ -227,32 +233,34 @@ internal class LocationAwareKLogger(override val underlyingLogger: LocationAware underlyingLogger.log(null, fqcn, LocationAwareLogger.WARN_INT, msg, null, t) } - override fun warn(marker: Marker?, msg: String?) { + override fun warn(marker: io.github.oshai.Marker?, msg: String?) { if (!underlyingLogger.isWarnEnabled) return - underlyingLogger.log(marker, fqcn, LocationAwareLogger.WARN_INT, msg, null, null) + underlyingLogger.log(marker?.toSlf4j(), fqcn, LocationAwareLogger.WARN_INT, msg, null, null) } - override fun warn(marker: Marker?, msg: String?, arg: Any?) { + override fun warn(marker: io.github.oshai.Marker?, msg: String?, arg: Any?) { if (!underlyingLogger.isWarnEnabled) return - underlyingLogger.log(marker, fqcn, LocationAwareLogger.WARN_INT, msg, arrayOf(arg), null) + underlyingLogger.log( + marker?.toSlf4j(), fqcn, LocationAwareLogger.WARN_INT, msg, arrayOf(arg), null) } - override fun warn(marker: Marker?, msg: String?, arg1: Any?, arg2: Any?) { + override fun warn(marker: io.github.oshai.Marker?, msg: String?, arg1: Any?, arg2: Any?) { if (!underlyingLogger.isWarnEnabled) return - underlyingLogger.log(marker, fqcn, LocationAwareLogger.WARN_INT, msg, arrayOf(arg1, arg2), null) + underlyingLogger.log( + marker?.toSlf4j(), fqcn, LocationAwareLogger.WARN_INT, msg, arrayOf(arg1, arg2), null) } - override fun warn(marker: Marker?, msg: String?, argArray: Array) { + override fun warn(marker: io.github.oshai.Marker?, msg: String?, vararg argArray: Any?) { if (!underlyingLogger.isWarnEnabled) return - underlyingLogger.log(marker, fqcn, LocationAwareLogger.WARN_INT, msg, argArray, null) + underlyingLogger.log(marker?.toSlf4j(), fqcn, LocationAwareLogger.WARN_INT, msg, argArray, null) } - override fun warn(marker: Marker?, msg: String?, t: Throwable?) { + override fun warn(marker: io.github.oshai.Marker?, msg: String?, t: Throwable?) { if (!underlyingLogger.isWarnEnabled) return - underlyingLogger.log(marker, fqcn, LocationAwareLogger.WARN_INT, msg, null, t) + underlyingLogger.log(marker?.toSlf4j(), fqcn, LocationAwareLogger.WARN_INT, msg, null, t) } override fun error(msg: String?) { @@ -273,7 +281,7 @@ internal class LocationAwareKLogger(override val underlyingLogger: LocationAware underlyingLogger.log(null, fqcn, LocationAwareLogger.ERROR_INT, msg, arrayOf(arg1, arg2), null) } - override fun error(msg: String?, argArray: Array) { + override fun error(msg: String?, vararg argArray: Any?) { if (!underlyingLogger.isErrorEnabled) return underlyingLogger.log(null, fqcn, LocationAwareLogger.ERROR_INT, msg, argArray, null) @@ -285,32 +293,34 @@ internal class LocationAwareKLogger(override val underlyingLogger: LocationAware underlyingLogger.log(null, fqcn, LocationAwareLogger.ERROR_INT, msg, null, t) } - override fun error(marker: Marker?, msg: String?) { + override fun error(marker: io.github.oshai.Marker?, msg: String?) { if (!underlyingLogger.isErrorEnabled) return - underlyingLogger.log(marker, fqcn, LocationAwareLogger.ERROR_INT, msg, null, null) + underlyingLogger.log(marker?.toSlf4j(), fqcn, LocationAwareLogger.ERROR_INT, msg, null, null) } - override fun error(marker: Marker?, msg: String?, arg: Any?) { + override fun error(marker: io.github.oshai.Marker?, msg: String?, arg: Any?) { if (!underlyingLogger.isErrorEnabled) return - underlyingLogger.log(marker, fqcn, LocationAwareLogger.ERROR_INT, msg, arrayOf(arg), null) + underlyingLogger.log( + marker?.toSlf4j(), fqcn, LocationAwareLogger.ERROR_INT, msg, arrayOf(arg), null) } - override fun error(marker: Marker?, msg: String?, arg1: Any?, arg2: Any?) { + override fun error(marker: io.github.oshai.Marker?, msg: String?, arg1: Any?, arg2: Any?) { if (!underlyingLogger.isErrorEnabled) return underlyingLogger.log( - marker, fqcn, LocationAwareLogger.ERROR_INT, msg, arrayOf(arg1, arg2), null) + marker?.toSlf4j(), fqcn, LocationAwareLogger.ERROR_INT, msg, arrayOf(arg1, arg2), null) } - override fun error(marker: Marker?, msg: String?, argArray: Array) { + override fun error(marker: io.github.oshai.Marker?, msg: String?, vararg argArray: Any?) { if (!underlyingLogger.isErrorEnabled) return - underlyingLogger.log(marker, fqcn, LocationAwareLogger.ERROR_INT, msg, argArray, null) + underlyingLogger.log( + marker?.toSlf4j(), fqcn, LocationAwareLogger.ERROR_INT, msg, argArray, null) } - override fun error(marker: Marker?, msg: String?, t: Throwable?) { + override fun error(marker: io.github.oshai.Marker?, msg: String?, t: Throwable?) { if (!underlyingLogger.isErrorEnabled) return - underlyingLogger.log(marker, fqcn, LocationAwareLogger.ERROR_INT, msg, null, t) + underlyingLogger.log(marker?.toSlf4j(), fqcn, LocationAwareLogger.ERROR_INT, msg, null, t) } /** Lazy add a log message if isTraceEnabled is true */ @@ -364,52 +374,52 @@ internal class LocationAwareKLogger(override val underlyingLogger: LocationAware } /** Lazy add a log message with a marker if isTraceEnabled is true */ - override fun trace(marker: Marker?, msg: () -> Any?) { + override fun trace(marker: io.github.oshai.Marker?, msg: () -> Any?) { if (isTraceEnabled) trace(marker, msg.toStringSafe()) } /** Lazy add a log message with a marker if isDebugEnabled is true */ - override fun debug(marker: Marker?, msg: () -> Any?) { + override fun debug(marker: io.github.oshai.Marker?, msg: () -> Any?) { if (isDebugEnabled) debug(marker, msg.toStringSafe()) } /** Lazy add a log message with a marker if isInfoEnabled is true */ - override fun info(marker: Marker?, msg: () -> Any?) { + override fun info(marker: io.github.oshai.Marker?, msg: () -> Any?) { if (isInfoEnabled) info(marker, msg.toStringSafe()) } /** Lazy add a log message with a marker if isWarnEnabled is true */ - override fun warn(marker: Marker?, msg: () -> Any?) { + override fun warn(marker: io.github.oshai.Marker?, msg: () -> Any?) { if (isWarnEnabled) warn(marker, msg.toStringSafe()) } /** Lazy add a log message with a marker if isErrorEnabled is true */ - override fun error(marker: Marker?, msg: () -> Any?) { + override fun error(marker: io.github.oshai.Marker?, msg: () -> Any?) { if (isErrorEnabled) error(marker, msg.toStringSafe()) } /** Lazy add a log message with a marker and throwable payload if isTraceEnabled is true */ - override fun trace(marker: Marker?, t: Throwable?, msg: () -> Any?) { + override fun trace(marker: io.github.oshai.Marker?, t: Throwable?, msg: () -> Any?) { if (isTraceEnabled) trace(marker, msg.toStringSafe(), t) } /** Lazy add a log message with a marker and throwable payload if isDebugEnabled is true */ - override fun debug(marker: Marker?, t: Throwable?, msg: () -> Any?) { + override fun debug(marker: io.github.oshai.Marker?, t: Throwable?, msg: () -> Any?) { if (isDebugEnabled) debug(marker, msg.toStringSafe(), t) } /** Lazy add a log message with a marker and throwable payload if isInfoEnabled is true */ - override fun info(marker: Marker?, t: Throwable?, msg: () -> Any?) { + override fun info(marker: io.github.oshai.Marker?, t: Throwable?, msg: () -> Any?) { if (isInfoEnabled) info(marker, msg.toStringSafe(), t) } /** Lazy add a log message with a marker and throwable payload if isWarnEnabled is true */ - override fun warn(marker: Marker?, t: Throwable?, msg: () -> Any?) { + override fun warn(marker: io.github.oshai.Marker?, t: Throwable?, msg: () -> Any?) { if (isWarnEnabled) warn(marker, msg.toStringSafe(), t) } /** Lazy add a log message with a marker and throwable payload if isErrorEnabled is true */ - override fun error(marker: Marker?, t: Throwable?, msg: () -> Any?) { + override fun error(marker: io.github.oshai.Marker?, t: Throwable?, msg: () -> Any?) { if (isErrorEnabled) error(marker, msg.toStringSafe(), t) } diff --git a/src/jvmMain/kotlin/io/github/oshai/slf4j/internal/LocationIgnorantKLogger.kt b/src/jvmMain/kotlin/io/github/oshai/slf4j/internal/LocationIgnorantKLogger.kt new file mode 100644 index 00000000..801778e8 --- /dev/null +++ b/src/jvmMain/kotlin/io/github/oshai/slf4j/internal/LocationIgnorantKLogger.kt @@ -0,0 +1,360 @@ +@file:Suppress("NOTHING_TO_INLINE", "OVERRIDE_BY_INLINE") + +package io.github.oshai.slf4j.internal + +import io.github.oshai.KLogger +import io.github.oshai.internal.toStringSafe +import io.github.oshai.slf4j.toSlf4j +import org.slf4j.Logger + +/** + * A class wrapping a [Logger] instance that is not location aware all methods of [KLogger] has + * default implementation the rest of the methods are delegated to [Logger] Hence no implemented + * methods + */ +@Suppress("TooManyFunctions") +internal class LocationIgnorantKLogger(override val underlyingLogger: Logger) : + Slf4jLoggerWrapper(underlyingLogger), io.github.oshai.KLogger { + + /** Lazy add a log message if isTraceEnabled is true */ + override fun trace(msg: () -> Any?) { + if (isTraceEnabled) trace(msg.toStringSafe()) + } + + /** Lazy add a log message if isDebugEnabled is true */ + override fun debug(msg: () -> Any?) { + if (isDebugEnabled) debug(msg.toStringSafe()) + } + + /** Lazy add a log message if isInfoEnabled is true */ + override fun info(msg: () -> Any?) { + if (isInfoEnabled) info(msg.toStringSafe()) + } + + /** Lazy add a log message if isWarnEnabled is true */ + override fun warn(msg: () -> Any?) { + if (isWarnEnabled) warn(msg.toStringSafe()) + } + + /** Lazy add a log message if isErrorEnabled is true */ + override fun error(msg: () -> Any?) { + if (isErrorEnabled) error(msg.toStringSafe()) + } + + /** Lazy add a log message with throwable payload if isTraceEnabled is true */ + override fun trace(t: Throwable?, msg: () -> Any?) { + if (isTraceEnabled) trace(msg.toStringSafe(), t) + } + + /** Lazy add a log message with throwable payload if isDebugEnabled is true */ + override fun debug(t: Throwable?, msg: () -> Any?) { + if (isDebugEnabled) debug(msg.toStringSafe(), t) + } + + /** Lazy add a log message with throwable payload if isInfoEnabled is true */ + override fun info(t: Throwable?, msg: () -> Any?) { + if (isInfoEnabled) info(msg.toStringSafe(), t) + } + + /** Lazy add a log message with throwable payload if isWarnEnabled is true */ + override fun warn(t: Throwable?, msg: () -> Any?) { + if (isWarnEnabled) warn(msg.toStringSafe(), t) + } + + /** Lazy add a log message with throwable payload if isErrorEnabled is true */ + override fun error(t: Throwable?, msg: () -> Any?) { + if (isErrorEnabled) error(msg.toStringSafe(), t) + } + + /** Lazy add a log message with a marker if isTraceEnabled is true */ + override fun trace(marker: io.github.oshai.Marker?, msg: () -> Any?) { + if (isTraceEnabled) trace(marker, msg.toStringSafe()) + } + + /** Lazy add a log message with a marker if isDebugEnabled is true */ + override fun debug(marker: io.github.oshai.Marker?, msg: () -> Any?) { + if (isDebugEnabled) debug(marker, msg.toStringSafe()) + } + + /** Lazy add a log message with a marker if isInfoEnabled is true */ + override fun info(marker: io.github.oshai.Marker?, msg: () -> Any?) { + if (isInfoEnabled) info(marker, msg.toStringSafe()) + } + + /** Lazy add a log message with a marker if isWarnEnabled is true */ + override fun warn(marker: io.github.oshai.Marker?, msg: () -> Any?) { + if (isWarnEnabled) warn(marker, msg.toStringSafe()) + } + + /** Lazy add a log message with a marker if isErrorEnabled is true */ + override fun error(marker: io.github.oshai.Marker?, msg: () -> Any?) { + if (isErrorEnabled) error(marker, msg.toStringSafe()) + } + + /** Lazy add a log message with a marker and throwable payload if isTraceEnabled is true */ + override fun trace(marker: io.github.oshai.Marker?, t: Throwable?, msg: () -> Any?) { + if (isTraceEnabled) trace(marker, msg.toStringSafe(), t) + } + + override fun trace(msg: String?) { + if (isTraceEnabled) { + underlyingLogger.trace(msg) + } + } + + override fun trace(format: String?, arg: Any?) { + underlyingLogger.trace(format, arg) + } + + override fun trace(format: String?, arg1: Any?, arg2: Any?) { + underlyingLogger.trace(format, arg1, arg2) + } + + override fun trace(format: String?, vararg arguments: Any?) { + underlyingLogger.trace(format, arguments) + } + + override fun trace(msg: String?, t: Throwable?) { + underlyingLogger.trace(msg, t) + } + + override fun trace(marker: io.github.oshai.Marker?, msg: String?) { + underlyingLogger.trace(marker?.toSlf4j(), msg) + } + + override fun trace(marker: io.github.oshai.Marker?, format: String?, arg: Any?) { + underlyingLogger.trace(marker?.toSlf4j(), format, arg) + } + + override fun trace(marker: io.github.oshai.Marker?, format: String?, arg1: Any?, arg2: Any?) { + underlyingLogger.trace(marker?.toSlf4j(), format, arg1, arg2) + } + + override fun trace(marker: io.github.oshai.Marker?, format: String?, vararg argArray: Any?) { + underlyingLogger.trace(marker?.toSlf4j(), format, argArray) + } + + override fun trace(marker: io.github.oshai.Marker?, msg: String?, t: Throwable?) { + underlyingLogger.trace(marker?.toSlf4j(), msg, t) + } + + /** Lazy add a log message with a marker and throwable payload if isDebugEnabled is true */ + override fun debug(marker: io.github.oshai.Marker?, t: Throwable?, msg: () -> Any?) { + if (isDebugEnabled) debug(marker, msg.toStringSafe(), t) + } + + override fun debug(msg: String?) { + if (isTraceEnabled) { + underlyingLogger.debug(msg) + } + } + + override fun debug(format: String?, arg: Any?) { + underlyingLogger.debug(format, arg) + } + + override fun debug(format: String?, arg1: Any?, arg2: Any?) { + underlyingLogger.debug(format, arg1, arg2) + } + + override fun debug(format: String?, vararg arguments: Any?) { + underlyingLogger.debug(format, arguments) + } + + override fun debug(msg: String?, t: Throwable?) { + underlyingLogger.debug(msg, t) + } + + override fun debug(marker: io.github.oshai.Marker?, msg: String?) { + underlyingLogger.debug(marker?.toSlf4j(), msg) + } + + override fun debug(marker: io.github.oshai.Marker?, format: String?, arg: Any?) { + underlyingLogger.debug(marker?.toSlf4j(), format, arg) + } + + override fun debug(marker: io.github.oshai.Marker?, format: String?, arg1: Any?, arg2: Any?) { + underlyingLogger.debug(marker?.toSlf4j(), format, arg1, arg2) + } + + override fun debug(marker: io.github.oshai.Marker?, format: String?, vararg argArray: Any?) { + underlyingLogger.debug(marker?.toSlf4j(), format, argArray) + } + + override fun debug(marker: io.github.oshai.Marker?, msg: String?, t: Throwable?) { + underlyingLogger.debug(marker?.toSlf4j(), msg, t) + } + + /** Lazy add a log message with a marker and throwable payload if isInfoEnabled is true */ + override fun info(marker: io.github.oshai.Marker?, t: Throwable?, msg: () -> Any?) { + if (isInfoEnabled) info(marker, msg.toStringSafe(), t) + } + + override fun info(msg: String?) { + if (isTraceEnabled) { + underlyingLogger.info(msg) + } + } + + override fun info(format: String?, arg: Any?) { + underlyingLogger.info(format, arg) + } + + override fun info(format: String?, arg1: Any?, arg2: Any?) { + underlyingLogger.info(format, arg1, arg2) + } + + override fun info(format: String?, vararg arguments: Any?) { + underlyingLogger.info(format, arguments) + } + + override fun info(msg: String?, t: Throwable?) { + underlyingLogger.info(msg, t) + } + + override fun info(marker: io.github.oshai.Marker?, msg: String?) { + underlyingLogger.info(marker?.toSlf4j(), msg) + } + + override fun info(marker: io.github.oshai.Marker?, format: String?, arg: Any?) { + underlyingLogger.info(marker?.toSlf4j(), format, arg) + } + + override fun info(marker: io.github.oshai.Marker?, format: String?, arg1: Any?, arg2: Any?) { + underlyingLogger.info(marker?.toSlf4j(), format, arg1, arg2) + } + + override fun info(marker: io.github.oshai.Marker?, format: String?, vararg argArray: Any?) { + underlyingLogger.info(marker?.toSlf4j(), format, argArray) + } + + override fun info(marker: io.github.oshai.Marker?, msg: String?, t: Throwable?) { + underlyingLogger.info(marker?.toSlf4j(), msg, t) + } + + /** Lazy add a log message with a marker and throwable payload if isWarnEnabled is true */ + override fun warn(marker: io.github.oshai.Marker?, t: Throwable?, msg: () -> Any?) { + if (isWarnEnabled) warn(marker, msg.toStringSafe(), t) + } + + override fun warn(msg: String?) { + if (isTraceEnabled) { + underlyingLogger.warn(msg) + } + } + + override fun warn(format: String?, arg: Any?) { + underlyingLogger.warn(format, arg) + } + + override fun warn(format: String?, arg1: Any?, arg2: Any?) { + underlyingLogger.warn(format, arg1, arg2) + } + + override fun warn(format: String?, vararg arguments: Any?) { + underlyingLogger.warn(format, arguments) + } + + override fun warn(msg: String?, t: Throwable?) { + underlyingLogger.warn(msg, t) + } + + override fun warn(marker: io.github.oshai.Marker?, msg: String?) { + underlyingLogger.warn(marker?.toSlf4j(), msg) + } + + override fun warn(marker: io.github.oshai.Marker?, format: String?, arg: Any?) { + underlyingLogger.warn(marker?.toSlf4j(), format, arg) + } + + override fun warn(marker: io.github.oshai.Marker?, format: String?, arg1: Any?, arg2: Any?) { + underlyingLogger.warn(marker?.toSlf4j(), format, arg1, arg2) + } + + override fun warn(marker: io.github.oshai.Marker?, format: String?, vararg argArray: Any?) { + underlyingLogger.warn(marker?.toSlf4j(), format, argArray) + } + + override fun warn(marker: io.github.oshai.Marker?, msg: String?, t: Throwable?) { + underlyingLogger.warn(marker?.toSlf4j(), msg, t) + } + + /** Lazy add a log message with a marker and throwable payload if isErrorEnabled is true */ + override fun error(marker: io.github.oshai.Marker?, t: Throwable?, msg: () -> Any?) { + if (isErrorEnabled) error(marker, msg.toStringSafe(), t) + } + + override fun error(msg: String?) { + if (isTraceEnabled) { + underlyingLogger.error(msg) + } + } + + override fun error(format: String?, arg: Any?) { + underlyingLogger.error(format, arg) + } + + override fun error(format: String?, arg1: Any?, arg2: Any?) { + underlyingLogger.error(format, arg1, arg2) + } + + override fun error(format: String?, vararg arguments: Any?) { + underlyingLogger.error(format, arguments) + } + + override fun error(msg: String?, t: Throwable?) { + underlyingLogger.error(msg, t) + } + + override fun error(marker: io.github.oshai.Marker?, msg: String?) { + underlyingLogger.error(marker?.toSlf4j(), msg) + } + + override fun error(marker: io.github.oshai.Marker?, format: String?, arg: Any?) { + underlyingLogger.error(marker?.toSlf4j(), format, arg) + } + + override fun error(marker: io.github.oshai.Marker?, format: String?, arg1: Any?, arg2: Any?) { + underlyingLogger.error(marker?.toSlf4j(), format, arg1, arg2) + } + + override fun error(marker: io.github.oshai.Marker?, format: String?, vararg argArray: Any?) { + underlyingLogger.error(marker?.toSlf4j(), format, argArray) + } + + override fun error(marker: io.github.oshai.Marker?, msg: String?, t: Throwable?) { + underlyingLogger.error(marker?.toSlf4j(), msg, t) + } + + override inline fun entry(vararg argArray: Any?) { + if (underlyingLogger.isTraceEnabled) { + underlyingLogger.trace("entry({})", argArray) + } + } + + override inline fun exit() { + if (underlyingLogger.isTraceEnabled) { + underlyingLogger.trace("exit") + } + } + + override inline fun exit(result: T): T { + if (underlyingLogger.isTraceEnabled) { + underlyingLogger.trace("exit({})", result) + } + return result + } + + override inline fun throwing(throwable: T): T { + if (underlyingLogger.isErrorEnabled) { + underlyingLogger.error("throwing($throwable)", throwable) + } + return throwable + } + + override inline fun catching(throwable: T) { + if (underlyingLogger.isErrorEnabled) { + underlyingLogger.error("catching($throwable)", throwable) + } + } +} diff --git a/src/jvmMain/kotlin/io/github/oshai/slf4j/internal/Slf4jLoggerFactory.kt b/src/jvmMain/kotlin/io/github/oshai/slf4j/internal/Slf4jLoggerFactory.kt new file mode 100644 index 00000000..013af0ca --- /dev/null +++ b/src/jvmMain/kotlin/io/github/oshai/slf4j/internal/Slf4jLoggerFactory.kt @@ -0,0 +1,17 @@ +package io.github.oshai.slf4j.internal + +import io.github.oshai.KLogger +import org.slf4j.Logger +import org.slf4j.LoggerFactory +import org.slf4j.spi.LocationAwareLogger + +internal object Slf4jLoggerFactory { + + /** get a java logger by name */ + fun jLogger(name: String): Logger = LoggerFactory.getLogger(name) + + /** wrap java logger based on location awareness */ + fun wrapJLogger(jLogger: Logger): KLogger = + if (jLogger is LocationAwareLogger) LocationAwareKLogger(jLogger) + else LocationIgnorantKLogger(jLogger) +} diff --git a/src/jvmMain/kotlin/io/github/oshai/slf4j/internal/Slf4jLoggerWrapper.kt b/src/jvmMain/kotlin/io/github/oshai/slf4j/internal/Slf4jLoggerWrapper.kt new file mode 100644 index 00000000..9c6bd437 --- /dev/null +++ b/src/jvmMain/kotlin/io/github/oshai/slf4j/internal/Slf4jLoggerWrapper.kt @@ -0,0 +1,47 @@ +package io.github.oshai.slf4j.internal + +import io.github.oshai.KLogger +import io.github.oshai.Marker +import io.github.oshai.slf4j.toSlf4j +import org.slf4j.Logger + +internal abstract class Slf4jLoggerWrapper(override val underlyingLogger: Logger) : KLogger { + + override val name: String + get() = underlyingLogger.name + + override val isTraceEnabled: Boolean + get() = underlyingLogger.isTraceEnabled + + override fun isTraceEnabled(marker: Marker?): Boolean { + return underlyingLogger.isTraceEnabled(marker?.toSlf4j()) + } + + override val isDebugEnabled: Boolean + get() = underlyingLogger.isDebugEnabled + + override fun isDebugEnabled(marker: Marker?): Boolean { + return underlyingLogger.isDebugEnabled(marker?.toSlf4j()) + } + + override val isInfoEnabled: Boolean + get() = underlyingLogger.isInfoEnabled + + override fun isInfoEnabled(marker: Marker?): Boolean { + return underlyingLogger.isInfoEnabled(marker?.toSlf4j()) + } + + override val isWarnEnabled: Boolean + get() = underlyingLogger.isWarnEnabled + + override fun isWarnEnabled(marker: Marker?): Boolean { + return underlyingLogger.isWarnEnabled(marker?.toSlf4j()) + } + + override val isErrorEnabled: Boolean + get() = underlyingLogger.isErrorEnabled + + override fun isErrorEnabled(marker: Marker?): Boolean { + return underlyingLogger.isErrorEnabled(marker?.toSlf4j()) + } +} diff --git a/src/jvmMain/kotlin/mu/KLogger.kt b/src/jvmMain/kotlin/mu/KLogger.kt deleted file mode 100644 index 53519efe..00000000 --- a/src/jvmMain/kotlin/mu/KLogger.kt +++ /dev/null @@ -1,91 +0,0 @@ -package mu - -import org.slf4j.Logger - -/** - * An extension for [Logger] with Lazy message evaluation example: - * ``` - * logger.info{"this is $lazy evaluated string"} - * ``` - */ -@Suppress("TooManyFunctions") -public actual interface KLogger : Logger { - - /** The actual logger executing logging */ - public val underlyingLogger: Logger - - /** Lazy add a log message if isTraceEnabled is true */ - public actual fun trace(msg: () -> Any?) - - /** Lazy add a log message if isDebugEnabled is true */ - public actual fun debug(msg: () -> Any?) - - /** Lazy add a log message if isInfoEnabled is true */ - public actual fun info(msg: () -> Any?) - - /** Lazy add a log message if isWarnEnabled is true */ - public actual fun warn(msg: () -> Any?) - - /** Lazy add a log message if isErrorEnabled is true */ - public actual fun error(msg: () -> Any?) - - /** Lazy add a log message with throwable payload if isTraceEnabled is true */ - public actual fun trace(t: Throwable?, msg: () -> Any?) - - /** Lazy add a log message with throwable payload if isDebugEnabled is true */ - public actual fun debug(t: Throwable?, msg: () -> Any?) - - /** Lazy add a log message with throwable payload if isInfoEnabled is true */ - public actual fun info(t: Throwable?, msg: () -> Any?) - - /** Lazy add a log message with throwable payload if isWarnEnabled is true */ - public actual fun warn(t: Throwable?, msg: () -> Any?) - - /** Lazy add a log message with throwable payload if isErrorEnabled is true */ - public actual fun error(t: Throwable?, msg: () -> Any?) - - /** Lazy add a log message if isTraceEnabled is true */ - public actual fun trace(marker: Marker?, msg: () -> Any?) - - /** Lazy add a log message if isDebugEnabled is true */ - public actual fun debug(marker: Marker?, msg: () -> Any?) - - /** Lazy add a log message if isInfoEnabled is true */ - public actual fun info(marker: Marker?, msg: () -> Any?) - - /** Lazy add a log message if isWarnEnabled is true */ - public actual fun warn(marker: Marker?, msg: () -> Any?) - - /** Lazy add a log message if isErrorEnabled is true */ - public actual fun error(marker: Marker?, msg: () -> Any?) - - /** Lazy add a log message with throwable payload if isTraceEnabled is true */ - public actual fun trace(marker: Marker?, t: Throwable?, msg: () -> Any?) - - /** Lazy add a log message with throwable payload if isDebugEnabled is true */ - public actual fun debug(marker: Marker?, t: Throwable?, msg: () -> Any?) - - /** Lazy add a log message with throwable payload if isInfoEnabled is true */ - public actual fun info(marker: Marker?, t: Throwable?, msg: () -> Any?) - - /** Lazy add a log message with throwable payload if isWarnEnabled is true */ - public actual fun warn(marker: Marker?, t: Throwable?, msg: () -> Any?) - - /** Lazy add a log message with throwable payload if isErrorEnabled is true */ - public actual fun error(marker: Marker?, t: Throwable?, msg: () -> Any?) - - /** Add a log message with all the supplied parameters along with method name */ - public actual fun entry(vararg argArray: Any?) - - /** Add log message indicating exit of a method */ - public actual fun exit() - - /** Add a log message with the return value of a method */ - public actual fun exit(result: T): T where T : Any? - - /** Add a log message indicating an exception will be thrown along with the stack trace. */ - public actual fun throwing(throwable: T): T where T : Throwable - - /** Add a log message indicating an exception is caught along with the stack trace. */ - public actual fun catching(throwable: T) where T : Throwable -} diff --git a/src/jvmMain/kotlin/mu/KMarkerFactory.kt b/src/jvmMain/kotlin/mu/KMarkerFactory.kt deleted file mode 100644 index 06cc9333..00000000 --- a/src/jvmMain/kotlin/mu/KMarkerFactory.kt +++ /dev/null @@ -1,8 +0,0 @@ -package mu - -import org.slf4j.MarkerFactory - -public actual object KMarkerFactory { - - public actual fun getMarker(name: String): Marker = MarkerFactory.getMarker(name) -} diff --git a/src/jvmMain/kotlin/mu/Marker.kt b/src/jvmMain/kotlin/mu/Marker.kt deleted file mode 100644 index 7ae78296..00000000 --- a/src/jvmMain/kotlin/mu/Marker.kt +++ /dev/null @@ -1,3 +0,0 @@ -package mu - -public actual typealias Marker = org.slf4j.Marker diff --git a/src/jvmMain/kotlin/mu/internal/KLoggerFactory.kt b/src/jvmMain/kotlin/mu/internal/KLoggerFactory.kt deleted file mode 100644 index 52880d0d..00000000 --- a/src/jvmMain/kotlin/mu/internal/KLoggerFactory.kt +++ /dev/null @@ -1,31 +0,0 @@ -package mu.internal - -import mu.KLoggable -import mu.KLogger -import org.slf4j.Logger -import org.slf4j.LoggerFactory -import org.slf4j.spi.LocationAwareLogger - -/** factory methods to obtain a [Logger] */ -@Suppress("NOTHING_TO_INLINE") -internal object KLoggerFactory { - - /** get logger for the class */ - internal inline fun logger(loggable: KLoggable): KLogger = - logger(KLoggerNameResolver.name(loggable.javaClass)) - - /** get logger by explicit name */ - internal inline fun logger(name: String): KLogger = wrapJLogger(jLogger(name)) - - /** get logger for the method, assuming it was declared at the logger file/class */ - internal inline fun logger(noinline func: () -> Unit): KLogger = - logger(KLoggerNameResolver.name(func)) - - /** get a java logger by name */ - private inline fun jLogger(name: String): Logger = LoggerFactory.getLogger(name) - - /** wrap java logger based on location awareness */ - internal inline fun wrapJLogger(jLogger: Logger): KLogger = - if (jLogger is LocationAwareLogger) LocationAwareKLogger(jLogger) - else LocationIgnorantKLogger(jLogger) -} diff --git a/src/jvmMain/kotlin/mu/internal/LocationIgnorantKLogger.kt b/src/jvmMain/kotlin/mu/internal/LocationIgnorantKLogger.kt deleted file mode 100644 index 18455e2b..00000000 --- a/src/jvmMain/kotlin/mu/internal/LocationIgnorantKLogger.kt +++ /dev/null @@ -1,149 +0,0 @@ -@file:Suppress("NOTHING_TO_INLINE", "OVERRIDE_BY_INLINE") - -package mu.internal - -import mu.KLogger -import org.slf4j.Logger -import org.slf4j.Marker - -/** - * A class wrapping a [Logger] instance that is not location aware all methods of [KLogger] has - * default implementation the rest of the methods are delegated to [Logger] Hence no implemented - * methods - */ -@Suppress("TooManyFunctions") -internal class LocationIgnorantKLogger(override val underlyingLogger: Logger) : - KLogger, Logger by underlyingLogger { - - /** Lazy add a log message if isTraceEnabled is true */ - override fun trace(msg: () -> Any?) { - if (isTraceEnabled) trace(msg.toStringSafe()) - } - - /** Lazy add a log message if isDebugEnabled is true */ - override fun debug(msg: () -> Any?) { - if (isDebugEnabled) debug(msg.toStringSafe()) - } - - /** Lazy add a log message if isInfoEnabled is true */ - override fun info(msg: () -> Any?) { - if (isInfoEnabled) info(msg.toStringSafe()) - } - - /** Lazy add a log message if isWarnEnabled is true */ - override fun warn(msg: () -> Any?) { - if (isWarnEnabled) warn(msg.toStringSafe()) - } - - /** Lazy add a log message if isErrorEnabled is true */ - override fun error(msg: () -> Any?) { - if (isErrorEnabled) error(msg.toStringSafe()) - } - - /** Lazy add a log message with throwable payload if isTraceEnabled is true */ - override fun trace(t: Throwable?, msg: () -> Any?) { - if (isTraceEnabled) trace(msg.toStringSafe(), t) - } - - /** Lazy add a log message with throwable payload if isDebugEnabled is true */ - override fun debug(t: Throwable?, msg: () -> Any?) { - if (isDebugEnabled) debug(msg.toStringSafe(), t) - } - - /** Lazy add a log message with throwable payload if isInfoEnabled is true */ - override fun info(t: Throwable?, msg: () -> Any?) { - if (isInfoEnabled) info(msg.toStringSafe(), t) - } - - /** Lazy add a log message with throwable payload if isWarnEnabled is true */ - override fun warn(t: Throwable?, msg: () -> Any?) { - if (isWarnEnabled) warn(msg.toStringSafe(), t) - } - - /** Lazy add a log message with throwable payload if isErrorEnabled is true */ - override fun error(t: Throwable?, msg: () -> Any?) { - if (isErrorEnabled) error(msg.toStringSafe(), t) - } - - /** Lazy add a log message with a marker if isTraceEnabled is true */ - override fun trace(marker: Marker?, msg: () -> Any?) { - if (isTraceEnabled) trace(marker, msg.toStringSafe()) - } - - /** Lazy add a log message with a marker if isDebugEnabled is true */ - override fun debug(marker: Marker?, msg: () -> Any?) { - if (isDebugEnabled) debug(marker, msg.toStringSafe()) - } - - /** Lazy add a log message with a marker if isInfoEnabled is true */ - override fun info(marker: Marker?, msg: () -> Any?) { - if (isInfoEnabled) info(marker, msg.toStringSafe()) - } - - /** Lazy add a log message with a marker if isWarnEnabled is true */ - override fun warn(marker: Marker?, msg: () -> Any?) { - if (isWarnEnabled) warn(marker, msg.toStringSafe()) - } - - /** Lazy add a log message with a marker if isErrorEnabled is true */ - override fun error(marker: Marker?, msg: () -> Any?) { - if (isErrorEnabled) error(marker, msg.toStringSafe()) - } - - /** Lazy add a log message with a marker and throwable payload if isTraceEnabled is true */ - override fun trace(marker: Marker?, t: Throwable?, msg: () -> Any?) { - if (isTraceEnabled) trace(marker, msg.toStringSafe(), t) - } - - /** Lazy add a log message with a marker and throwable payload if isDebugEnabled is true */ - override fun debug(marker: Marker?, t: Throwable?, msg: () -> Any?) { - if (isDebugEnabled) debug(marker, msg.toStringSafe(), t) - } - - /** Lazy add a log message with a marker and throwable payload if isInfoEnabled is true */ - override fun info(marker: Marker?, t: Throwable?, msg: () -> Any?) { - if (isInfoEnabled) info(marker, msg.toStringSafe(), t) - } - - /** Lazy add a log message with a marker and throwable payload if isWarnEnabled is true */ - override fun warn(marker: Marker?, t: Throwable?, msg: () -> Any?) { - if (isWarnEnabled) warn(marker, msg.toStringSafe(), t) - } - - /** Lazy add a log message with a marker and throwable payload if isErrorEnabled is true */ - override fun error(marker: Marker?, t: Throwable?, msg: () -> Any?) { - if (isErrorEnabled) error(marker, msg.toStringSafe(), t) - } - - override inline fun entry(vararg argArray: Any?) { - if (underlyingLogger.isTraceEnabled) { - underlyingLogger.trace("entry({})", argArray) - } - } - - override inline fun exit() { - if (underlyingLogger.isTraceEnabled) { - underlyingLogger.trace("exit") - } - } - - override inline fun exit(result: T): T { - if (underlyingLogger.isTraceEnabled) { - underlyingLogger.trace("exit({})", result) - } - return result - } - - override inline fun throwing(throwable: T): T { - if (underlyingLogger.isErrorEnabled) { - underlyingLogger.error("throwing($throwable)", throwable) - } - return throwable - } - - override inline fun catching(throwable: T) { - if (underlyingLogger.isErrorEnabled) { - underlyingLogger.error("catching($throwable)", throwable) - } - } -} diff --git a/src/jvmTest/kotlin/mu/ClassWithLoggingForLocationTesting.kt b/src/jvmTest/kotlin/io/github/oshai/ClassWithLoggingForLocationTesting.kt similarity index 95% rename from src/jvmTest/kotlin/mu/ClassWithLoggingForLocationTesting.kt rename to src/jvmTest/kotlin/io/github/oshai/ClassWithLoggingForLocationTesting.kt index c99a1354..0658ba45 100644 --- a/src/jvmTest/kotlin/mu/ClassWithLoggingForLocationTesting.kt +++ b/src/jvmTest/kotlin/io/github/oshai/ClassWithLoggingForLocationTesting.kt @@ -1,4 +1,4 @@ -package mu +package io.github.oshai class ClassWithLoggingForLocationTesting { companion object : KLogging() diff --git a/src/jvmTest/kotlin/mu/KotlinLoggingMDCTest.kt b/src/jvmTest/kotlin/io/github/oshai/KotlinLoggingMDCTest.kt similarity index 99% rename from src/jvmTest/kotlin/mu/KotlinLoggingMDCTest.kt rename to src/jvmTest/kotlin/io/github/oshai/KotlinLoggingMDCTest.kt index 7135ffd8..7d5c49f5 100644 --- a/src/jvmTest/kotlin/mu/KotlinLoggingMDCTest.kt +++ b/src/jvmTest/kotlin/io/github/oshai/KotlinLoggingMDCTest.kt @@ -1,4 +1,4 @@ -package mu +package io.github.oshai import org.apache.logging.log4j.Level import org.apache.logging.log4j.core.config.Configurator diff --git a/src/jvmTest/kotlin/io/github/oshai/KotlinLoggingTest.kt b/src/jvmTest/kotlin/io/github/oshai/KotlinLoggingTest.kt new file mode 100644 index 00000000..3ddb0f7d --- /dev/null +++ b/src/jvmTest/kotlin/io/github/oshai/KotlinLoggingTest.kt @@ -0,0 +1,42 @@ +package io.github.oshai + +import io.github.oshai.slf4j.logger +import io.github.oshai.slf4j.toKLogger +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertAll +import org.slf4j.LoggerFactory + +private val logger = KotlinLogging.logger {} +private val loggerFromSlf4j = + KotlinLogging.logger(LoggerFactory.getLogger("io.github.oshai.slf4jLogger")) +private val loggerFromSlf4jExtension = + LoggerFactory.getLogger("io.github.oshai.slf4jLoggerExtension").toKLogger() + +class ForKotlinLoggingTest { + val loggerInClass = KotlinLogging.logger {} + + companion object { + val loggerInCompanion = KotlinLogging.logger {} + } +} + +class KotlinLoggingTest { + + @Test + fun testLoggerName() { + assertAll( + { assertEquals("io.github.oshai.KotlinLoggingTest", logger.name) }, + { + assertEquals( + "io.github.oshai.ForKotlinLoggingTest", ForKotlinLoggingTest().loggerInClass.name) + }, + { + assertEquals( + "io.github.oshai.ForKotlinLoggingTest", ForKotlinLoggingTest.loggerInCompanion.name) + }, + { assertEquals("io.github.oshai.slf4jLogger", loggerFromSlf4j.name) }, + { assertEquals("io.github.oshai.slf4jLoggerExtension", loggerFromSlf4jExtension.name) }, + ) + } +} diff --git a/src/jvmTest/kotlin/mu/LoggingTest.kt b/src/jvmTest/kotlin/io/github/oshai/LoggingTest.kt similarity index 70% rename from src/jvmTest/kotlin/mu/LoggingTest.kt rename to src/jvmTest/kotlin/io/github/oshai/LoggingTest.kt index 0f895cba..7dc36036 100644 --- a/src/jvmTest/kotlin/mu/LoggingTest.kt +++ b/src/jvmTest/kotlin/io/github/oshai/LoggingTest.kt @@ -1,4 +1,4 @@ -package mu +package io.github.oshai import java.io.StringWriter import org.apache.logging.log4j.Level @@ -62,7 +62,7 @@ open class ClassHasLogging : KLoggable { class ClassInheritLogging : ClassHasLogging() class ClassWithNamedLogging { - companion object : Any(), KLoggable by NamedKLogging("mu.ClassWithNamedLogging") + companion object : Any(), KLoggable by NamedKLogging("io.github.oshai.ClassWithNamedLogging") fun test() { logger.info { "test ClassWithNamedLogging" } @@ -151,13 +151,23 @@ class LoggingTest { .replace("\n\n", "\n") .split("\n") assertAll( - { assertEquals("INFO mu.ClassWithLogging - test ClassWithLogging", lines[0].trim()) }, - { assertEquals("TRACE mu.ClassWithLogging - test ClassWithLogging", lines[1].trim()) }, + { + assertEquals( + "INFO io.github.oshai.ClassWithLogging - test ClassWithLogging", lines[0].trim()) + }, + { + assertEquals( + "TRACE io.github.oshai.ClassWithLogging - test ClassWithLogging", lines[1].trim()) + }, { assertEquals("java.lang.Throwable: null", lines[2].trim()) }, - { assertTrue(lines[3].trim().startsWith("at mu.ClassWithLogging.testThrowable(")) }, + { + assertTrue( + lines[3].trim().startsWith("at io.github.oshai.ClassWithLogging.testThrowable(")) + }, { assertEquals( - "TRACE mu.ClassWithLogging - test ClassWithLogging", lines[lines.size - 1].trim()) + "TRACE io.github.oshai.ClassWithLogging - test ClassWithLogging", + lines[lines.size - 1].trim()) }, ) } @@ -178,13 +188,22 @@ class LoggingTest { .split("\n") assertAll( { - assertEquals("TRACE mu.ClassWithLogging MARKER - test ClassWithLogging", lines[0].trim()) + assertEquals( + "TRACE io.github.oshai.ClassWithLogging MARKER - test ClassWithLogging", + lines[0].trim()) }, { - assertEquals("TRACE mu.ClassWithLogging MARKER - test ClassWithLogging", lines[1].trim()) + assertEquals( + "TRACE io.github.oshai.ClassWithLogging MARKER - test ClassWithLogging", + lines[1].trim()) }, { assertEquals("java.lang.Throwable: null", lines[2].trim()) }, - { assertTrue(lines[3].trim().startsWith("at mu.ClassWithLogging.testMarkerThrowable(")) }, + { + assertTrue( + lines[3] + .trim() + .startsWith("at io.github.oshai.ClassWithLogging.testMarkerThrowable(")) + }, ) } @@ -193,7 +212,7 @@ class LoggingTest { ClassInheritLogging().test() appenderWithWriter.writer.flush() assertEquals( - "INFO mu.ClassInheritLogging - test ClassHasLogging", + "INFO io.github.oshai.ClassInheritLogging - test ClassHasLogging", appenderWithWriter.writer.toString().trim()) } @@ -202,7 +221,7 @@ class LoggingTest { ChildClassWithLogging().test() appenderWithWriter.writer.flush() assertEquals( - "INFO mu.ChildClassWithLogging - test ChildClassWithLogging", + "INFO io.github.oshai.ChildClassWithLogging - test ChildClassWithLogging", appenderWithWriter.writer.toString().trim()) } @@ -211,7 +230,7 @@ class LoggingTest { ClassWithNamedLogging().test() appenderWithWriter.writer.flush() assertEquals( - "INFO mu.ClassWithNamedLogging - test ClassWithNamedLogging", + "INFO io.github.oshai.ClassWithNamedLogging - test ClassWithNamedLogging", appenderWithWriter.writer.toString().trim()) } @@ -220,7 +239,7 @@ class LoggingTest { ClassHasLogging().test() appenderWithWriter.writer.flush() assertEquals( - "INFO mu.ClassHasLogging - test ClassHasLogging", + "INFO io.github.oshai.ClassHasLogging - test ClassHasLogging", appenderWithWriter.writer.toString().trim()) } @@ -229,7 +248,7 @@ class LoggingTest { CompanionHasLogging().test() appenderWithWriter.writer.flush() assertEquals( - "INFO mu.CompanionHasLogging - test CompanionHasLogging", + "INFO io.github.oshai.CompanionHasLogging - test CompanionHasLogging", appenderWithWriter.writer.toString().trim()) } @@ -238,7 +257,7 @@ class LoggingTest { LambdaRaisesError().test() appenderWithWriter.writer.flush() assertEquals( - "INFO mu.LambdaRaisesError - Log message invocation failed: java.lang.NullPointerException", + "INFO io.github.oshai.LambdaRaisesError - Log message invocation failed: java.lang.NullPointerException", appenderWithWriter.writer.toString().trim()) } @@ -247,13 +266,15 @@ class LoggingTest { ClassWithLogging().testFormatting() appenderWithWriter.writer.flush() assertEquals( - "INFO mu.ClassWithLogging - Message: String with {} curly braces", + "INFO io.github.oshai.ClassWithLogging - Message: String with {} curly braces", appenderWithWriter.writer.toString().trim()) } @Test fun `check underlyingLogger property`() { - assertEquals("mu.ClassHasLogging", ClassHasLogging().logger.underlyingLogger.name) + assertEquals( + "io.github.oshai.ClassHasLogging", + (ClassHasLogging().logger.underlyingLogger as org.slf4j.Logger).name) } } @@ -261,12 +282,16 @@ class LoggingNameTest { @Test fun testNames() { assertAll( - { assertEquals("mu.ClassWithLogging", ClassWithLogging.logger.name) }, - { assertEquals("mu.ClassInheritLogging", ClassInheritLogging().logger.name) }, - { assertEquals("mu.ChildClassWithLogging", ChildClassWithLogging.logger.name) }, - { assertEquals("mu.ClassWithNamedLogging", ClassWithNamedLogging.logger.name) }, - { assertEquals("mu.ClassHasLogging", ClassHasLogging().logger.name) }, - { assertEquals("mu.CompanionHasLogging", CompanionHasLogging.logger.name) }, + { assertEquals("io.github.oshai.ClassWithLogging", ClassWithLogging.logger.name) }, + { assertEquals("io.github.oshai.ClassInheritLogging", ClassInheritLogging().logger.name) }, + { + assertEquals("io.github.oshai.ChildClassWithLogging", ChildClassWithLogging.logger.name) + }, + { + assertEquals("io.github.oshai.ClassWithNamedLogging", ClassWithNamedLogging.logger.name) + }, + { assertEquals("io.github.oshai.ClassHasLogging", ClassHasLogging().logger.name) }, + { assertEquals("io.github.oshai.CompanionHasLogging", CompanionHasLogging.logger.name) }, ) } } diff --git a/src/jvmTest/kotlin/mu/LoggingWithLocationTest.kt b/src/jvmTest/kotlin/io/github/oshai/LoggingWithLocationTest.kt similarity index 99% rename from src/jvmTest/kotlin/mu/LoggingWithLocationTest.kt rename to src/jvmTest/kotlin/io/github/oshai/LoggingWithLocationTest.kt index 48f73e8e..71cc1654 100644 --- a/src/jvmTest/kotlin/mu/LoggingWithLocationTest.kt +++ b/src/jvmTest/kotlin/io/github/oshai/LoggingWithLocationTest.kt @@ -1,4 +1,4 @@ -package mu +package io.github.oshai import org.apache.logging.log4j.Level import org.apache.logging.log4j.core.config.Configurator diff --git a/src/jvmTest/kotlin/mu/internal/KLoggerNameResolverTest.kt b/src/jvmTest/kotlin/io/github/oshai/internal/KLoggerNameResolverTest.kt similarity index 54% rename from src/jvmTest/kotlin/mu/internal/KLoggerNameResolverTest.kt rename to src/jvmTest/kotlin/io/github/oshai/internal/KLoggerNameResolverTest.kt index 296d9dea..4c4c4b2d 100644 --- a/src/jvmTest/kotlin/mu/internal/KLoggerNameResolverTest.kt +++ b/src/jvmTest/kotlin/io/github/oshai/internal/KLoggerNameResolverTest.kt @@ -1,4 +1,4 @@ -package mu.internal +package io.github.oshai.internal import java.util.stream.Stream import org.junit.jupiter.api.Assertions.assertEquals @@ -18,29 +18,31 @@ class KLoggerNameResolverTest { private fun testNames(): Stream = Stream.of( - Arguments.of("mu.internal.BaseClass", BaseClass::class.java), - Arguments.of("mu.internal.ChildClass", ChildClass::class.java), - Arguments.of("mu.internal.BaseClass", BaseClass.Companion::class.java), - Arguments.of("mu.internal.ChildClass", ChildClass.Companion::class.java), - Arguments.of("mu.internal.Singleton", Singleton::class.java), - Arguments.of("mu.internal.MyInterface", MyInterface::class.java), + Arguments.of("io.github.oshai.internal.BaseClass", BaseClass::class.java), + Arguments.of("io.github.oshai.internal.ChildClass", ChildClass::class.java), + Arguments.of("io.github.oshai.internal.BaseClass", BaseClass.Companion::class.java), + Arguments.of("io.github.oshai.internal.ChildClass", ChildClass.Companion::class.java), + Arguments.of("io.github.oshai.internal.Singleton", Singleton::class.java), + Arguments.of("io.github.oshai.internal.MyInterface", MyInterface::class.java), Arguments.of("java.lang.Object", Any().javaClass), - Arguments.of("mu.internal.KLoggerNameResolverTest\$testNames$1", object {}.javaClass), Arguments.of( - "mu.internal.BaseClass\$InnerClass\$Obj", + "io.github.oshai.internal.KLoggerNameResolverTest\$testNames$1", object {}.javaClass), + Arguments.of( + "io.github.oshai.internal.BaseClass\$InnerClass\$Obj", BaseClass.InnerClass.Obj::class.java, ), Arguments.of( - "mu.internal.BaseClass\$InnerClass\$Obj", + "io.github.oshai.internal.BaseClass\$InnerClass\$Obj", BaseClass.InnerClass.Obj.javaClass, ), Arguments.of( - "mu.internal.BaseClass\$InnerClass", + "io.github.oshai.internal.BaseClass\$InnerClass", BaseClass.InnerClass.CmpObj::class.java, ), - Arguments.of("mu.internal.Foo\$Bar", Foo.Bar::class.java), - Arguments.of("mu.internal.Foo\$Bar2", Foo.Bar3.javaClass), - Arguments.of("mu.internal.PrivateCompanion", PrivateCompanion().companionClass)) + Arguments.of("io.github.oshai.internal.Foo\$Bar", Foo.Bar::class.java), + Arguments.of("io.github.oshai.internal.Foo\$Bar2", Foo.Bar3.javaClass), + Arguments.of( + "io.github.oshai.internal.PrivateCompanion", PrivateCompanion().companionClass)) } open class BaseClass { diff --git a/src/jvmTest/kotlin/mu/internal/MessageInvokerJavaTest.kt b/src/jvmTest/kotlin/io/github/oshai/internal/MessageInvokerJavaTest.kt similarity index 95% rename from src/jvmTest/kotlin/mu/internal/MessageInvokerJavaTest.kt rename to src/jvmTest/kotlin/io/github/oshai/internal/MessageInvokerJavaTest.kt index 4dc53979..4d2b7989 100644 --- a/src/jvmTest/kotlin/mu/internal/MessageInvokerJavaTest.kt +++ b/src/jvmTest/kotlin/io/github/oshai/internal/MessageInvokerJavaTest.kt @@ -1,4 +1,4 @@ -package mu.internal +package io.github.oshai.internal import kotlin.test.assertEquals import org.junit.jupiter.api.Test diff --git a/src/jvmTest/kotlin/io/github/oshai/jul/internal/JulLoggerWrapperTest.kt b/src/jvmTest/kotlin/io/github/oshai/jul/internal/JulLoggerWrapperTest.kt new file mode 100644 index 00000000..c6d2d1fd --- /dev/null +++ b/src/jvmTest/kotlin/io/github/oshai/jul/internal/JulLoggerWrapperTest.kt @@ -0,0 +1,56 @@ +package io.github.oshai.jul.internal + +import io.github.oshai.AppenderWithWriter +import io.github.oshai.KLogger +import io.github.oshai.KotlinLogging +import io.github.oshai.addAppender +import io.github.oshai.removeAppender +import java.util.logging.Level +import java.util.logging.Logger +import org.junit.jupiter.api.AfterAll +import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.BeforeAll +import org.junit.jupiter.api.Test +import org.slf4j.bridge.SLF4JBridgeHandler + +class JulLoggerWrapperTest { + + companion object { + private lateinit var logger: KLogger + private val appenderWithWriter: AppenderWithWriter = AppenderWithWriter() + + @BeforeAll + @JvmStatic + fun init() { + // our jul test just forward the logs jul -> slf4j -> log4j + SLF4JBridgeHandler.removeHandlersForRootLogger() + SLF4JBridgeHandler.install() + Logger.getLogger("").level = Level.FINEST + System.setProperty("kotlin-logging-to-jul", "true") + addAppender(appenderWithWriter.appender) + logger = KotlinLogging.logger {} + } + + @AfterAll + @JvmStatic + fun teardown() { + System.clearProperty("kotlin-logging-to-jul") + removeAppender(appenderWithWriter.appender) + } + } + + @Test + fun testJulLogger() { + assertTrue(logger is JulLoggerWrapper) + logger.info("simple jul message") + appenderWithWriter.writer.flush() + assertEquals( + "INFO io.github.oshai.jul.internal.JulLoggerWrapperTest - simple jul message", + appenderWithWriter.writer + .toString() + .trim() + .replace("\r", "\n") + .replace("\n\n", "\n") + .split("\n")[1]) + } +} diff --git a/src/jvmTest/kotlin/mu/KotlinLoggingTest.kt b/src/jvmTest/kotlin/mu/KotlinLoggingTest.kt deleted file mode 100644 index 595b9da1..00000000 --- a/src/jvmTest/kotlin/mu/KotlinLoggingTest.kt +++ /dev/null @@ -1,33 +0,0 @@ -package mu - -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.assertAll -import org.slf4j.LoggerFactory - -private val logger = KotlinLogging.logger {} -private val loggerFromSlf4j = KotlinLogging.logger(LoggerFactory.getLogger("mu.slf4jLogger")) -private val loggerFromSlf4jExtension = - LoggerFactory.getLogger("mu.slf4jLoggerExtension").toKLogger() - -class ForKotlinLoggingTest { - val loggerInClass = KotlinLogging.logger {} - - companion object { - val loggerInCompanion = KotlinLogging.logger {} - } -} - -class KotlinLoggingTest { - - @Test - fun testLoggerName() { - assertAll( - { assertEquals("mu.KotlinLoggingTest", logger.name) }, - { assertEquals("mu.ForKotlinLoggingTest", ForKotlinLoggingTest().loggerInClass.name) }, - { assertEquals("mu.ForKotlinLoggingTest", ForKotlinLoggingTest.loggerInCompanion.name) }, - { assertEquals("mu.slf4jLogger", loggerFromSlf4j.name) }, - { assertEquals("mu.slf4jLoggerExtension", loggerFromSlf4jExtension.name) }, - ) - } -} diff --git a/src/linuxMain/kotlin/mu/KotlinLoggingConfiguration.kt b/src/linuxMain/kotlin/io/github/oshai/KotlinLoggingConfiguration.kt similarity index 74% rename from src/linuxMain/kotlin/mu/KotlinLoggingConfiguration.kt rename to src/linuxMain/kotlin/io/github/oshai/KotlinLoggingConfiguration.kt index 7f23ccd0..681ffe74 100644 --- a/src/linuxMain/kotlin/mu/KotlinLoggingConfiguration.kt +++ b/src/linuxMain/kotlin/io/github/oshai/KotlinLoggingConfiguration.kt @@ -1,3 +1,3 @@ -package mu +package io.github.oshai public actual val DefaultAppender: Appender = ConsoleOutputAppender diff --git a/src/nativeMain/kotlin/mu/Appender.kt b/src/nativeMain/kotlin/io/github/oshai/Appender.kt similarity index 93% rename from src/nativeMain/kotlin/mu/Appender.kt rename to src/nativeMain/kotlin/io/github/oshai/Appender.kt index 664d72ac..ac7e0b8d 100644 --- a/src/nativeMain/kotlin/mu/Appender.kt +++ b/src/nativeMain/kotlin/io/github/oshai/Appender.kt @@ -1,4 +1,4 @@ -package mu +package io.github.oshai public interface Appender { public val includePrefix: Boolean diff --git a/src/nativeMain/kotlin/mu/ConsoleOutputAppender.kt b/src/nativeMain/kotlin/io/github/oshai/ConsoleOutputAppender.kt similarity index 96% rename from src/nativeMain/kotlin/mu/ConsoleOutputAppender.kt rename to src/nativeMain/kotlin/io/github/oshai/ConsoleOutputAppender.kt index e5494a0c..45bd5bdf 100644 --- a/src/nativeMain/kotlin/mu/ConsoleOutputAppender.kt +++ b/src/nativeMain/kotlin/io/github/oshai/ConsoleOutputAppender.kt @@ -1,4 +1,4 @@ -package mu +package io.github.oshai import platform.posix.fprintf import platform.posix.stderr diff --git a/src/nativeMain/kotlin/mu/DefaultMessageFormatter.kt b/src/nativeMain/kotlin/io/github/oshai/DefaultMessageFormatter.kt similarity index 82% rename from src/nativeMain/kotlin/mu/DefaultMessageFormatter.kt rename to src/nativeMain/kotlin/io/github/oshai/DefaultMessageFormatter.kt index 5906ca61..7ce6b687 100644 --- a/src/nativeMain/kotlin/mu/DefaultMessageFormatter.kt +++ b/src/nativeMain/kotlin/io/github/oshai/DefaultMessageFormatter.kt @@ -1,18 +1,18 @@ -package mu +package io.github.oshai -import mu.internal.toStringSafe +import io.github.oshai.internal.toStringSafe public object DefaultMessageFormatter : Formatter { public override fun formatMessage( includePrefix: Boolean, - level: KotlinLoggingLevel, + level: io.github.oshai.Level, loggerName: String, msg: () -> Any? ): String = "${prefix(includePrefix, level, loggerName)}${msg.toStringSafe()}" public override fun formatMessage( includePrefix: Boolean, - level: KotlinLoggingLevel, + level: io.github.oshai.Level, loggerName: String, t: Throwable?, msg: () -> Any? @@ -21,18 +21,18 @@ public object DefaultMessageFormatter : Formatter { public override fun formatMessage( includePrefix: Boolean, - level: KotlinLoggingLevel, + level: io.github.oshai.Level, loggerName: String, - marker: Marker?, + marker: io.github.oshai.Marker?, msg: () -> Any? ): String = "${prefix(includePrefix, level, loggerName)}${marker?.getName()} ${msg.toStringSafe()}" public override fun formatMessage( includePrefix: Boolean, - level: KotlinLoggingLevel, + level: io.github.oshai.Level, loggerName: String, - marker: Marker?, + marker: io.github.oshai.Marker?, t: Throwable?, msg: () -> Any? ): String = @@ -40,7 +40,7 @@ public object DefaultMessageFormatter : Formatter { private fun prefix( includePrefix: Boolean, - level: KotlinLoggingLevel, + level: io.github.oshai.Level, loggerName: String ): String { return if (includePrefix) { diff --git a/src/nativeMain/kotlin/mu/Formatter.kt b/src/nativeMain/kotlin/io/github/oshai/Formatter.kt similarity index 68% rename from src/nativeMain/kotlin/mu/Formatter.kt rename to src/nativeMain/kotlin/io/github/oshai/Formatter.kt index 0ff3cadd..c35db209 100644 --- a/src/nativeMain/kotlin/mu/Formatter.kt +++ b/src/nativeMain/kotlin/io/github/oshai/Formatter.kt @@ -1,31 +1,31 @@ -package mu +package io.github.oshai public interface Formatter { public fun formatMessage( includePrefix: Boolean, - level: KotlinLoggingLevel, + level: io.github.oshai.Level, loggerName: String, msg: () -> Any? ): String public fun formatMessage( includePrefix: Boolean, - level: KotlinLoggingLevel, + level: io.github.oshai.Level, loggerName: String, t: Throwable?, msg: () -> Any? ): String public fun formatMessage( includePrefix: Boolean, - level: KotlinLoggingLevel, + level: io.github.oshai.Level, loggerName: String, - marker: Marker?, + marker: io.github.oshai.Marker?, msg: () -> Any? ): String public fun formatMessage( includePrefix: Boolean, - level: KotlinLoggingLevel, + level: io.github.oshai.Level, loggerName: String, - marker: Marker?, + marker: io.github.oshai.Marker?, t: Throwable?, msg: () -> Any? ): String diff --git a/src/nativeMain/kotlin/mu/KLogger.kt b/src/nativeMain/kotlin/io/github/oshai/KLogger.kt similarity index 72% rename from src/nativeMain/kotlin/mu/KLogger.kt rename to src/nativeMain/kotlin/io/github/oshai/KLogger.kt index 8228bd47..e63323cb 100644 --- a/src/nativeMain/kotlin/mu/KLogger.kt +++ b/src/nativeMain/kotlin/io/github/oshai/KLogger.kt @@ -1,7 +1,13 @@ -package mu +package io.github.oshai public actual interface KLogger { + /** + * Return the name of this `Logger` instance. + * @return name of this logger instance + */ + public actual val name: String + /** Lazy add a log message if isTraceEnabled is true */ public actual fun trace(msg: () -> Any?) @@ -33,34 +39,34 @@ public actual interface KLogger { public actual fun error(t: Throwable?, msg: () -> Any?) /** Lazy add a log message if isTraceEnabled is true */ - public actual fun trace(marker: Marker?, msg: () -> Any?) + public actual fun trace(marker: io.github.oshai.Marker?, msg: () -> Any?) /** Lazy add a log message if isDebugEnabled is true */ - public actual fun debug(marker: Marker?, msg: () -> Any?) + public actual fun debug(marker: io.github.oshai.Marker?, msg: () -> Any?) /** Lazy add a log message if isInfoEnabled is true */ - public actual fun info(marker: Marker?, msg: () -> Any?) + public actual fun info(marker: io.github.oshai.Marker?, msg: () -> Any?) /** Lazy add a log message if isWarnEnabled is true */ - public actual fun warn(marker: Marker?, msg: () -> Any?) + public actual fun warn(marker: io.github.oshai.Marker?, msg: () -> Any?) /** Lazy add a log message if isErrorEnabled is true */ - public actual fun error(marker: Marker?, msg: () -> Any?) + public actual fun error(marker: io.github.oshai.Marker?, msg: () -> Any?) /** Lazy add a log message with throwable payload if isTraceEnabled is true */ - public actual fun trace(marker: Marker?, t: Throwable?, msg: () -> Any?) + public actual fun trace(marker: io.github.oshai.Marker?, t: Throwable?, msg: () -> Any?) /** Lazy add a log message with throwable payload if isDebugEnabled is true */ - public actual fun debug(marker: Marker?, t: Throwable?, msg: () -> Any?) + public actual fun debug(marker: io.github.oshai.Marker?, t: Throwable?, msg: () -> Any?) /** Lazy add a log message with throwable payload if isInfoEnabled is true */ - public actual fun info(marker: Marker?, t: Throwable?, msg: () -> Any?) + public actual fun info(marker: io.github.oshai.Marker?, t: Throwable?, msg: () -> Any?) /** Lazy add a log message with throwable payload if isWarnEnabled is true */ - public actual fun warn(marker: Marker?, t: Throwable?, msg: () -> Any?) + public actual fun warn(marker: io.github.oshai.Marker?, t: Throwable?, msg: () -> Any?) /** Lazy add a log message with throwable payload if isErrorEnabled is true */ - public actual fun error(marker: Marker?, t: Throwable?, msg: () -> Any?) + public actual fun error(marker: io.github.oshai.Marker?, t: Throwable?, msg: () -> Any?) /** Add a log message with all the supplied parameters along with method name */ public actual fun entry(vararg argArray: Any?) diff --git a/src/nativeMain/kotlin/mu/KotlinLogging.kt b/src/nativeMain/kotlin/io/github/oshai/KotlinLogging.kt similarity index 51% rename from src/nativeMain/kotlin/mu/KotlinLogging.kt rename to src/nativeMain/kotlin/io/github/oshai/KotlinLogging.kt index 26b17971..228a7190 100644 --- a/src/nativeMain/kotlin/mu/KotlinLogging.kt +++ b/src/nativeMain/kotlin/io/github/oshai/KotlinLogging.kt @@ -1,6 +1,6 @@ -package mu +package io.github.oshai -import mu.internal.KLoggerLinux +import io.github.oshai.internal.KLoggerLinux public actual object KotlinLogging { /** @@ -9,8 +9,8 @@ public actual object KotlinLogging { * val logger = KotlinLogging.logger {} * ``` */ - public actual fun logger(func: () -> Unit): KLogger = + public actual fun logger(func: () -> Unit): io.github.oshai.KLogger = KLoggerLinux(func::class.qualifiedName ?: "") - public actual fun logger(name: String): KLogger = KLoggerLinux(name) + public actual fun logger(name: String): io.github.oshai.KLogger = KLoggerLinux(name) } diff --git a/src/nativeMain/kotlin/mu/KotlinLoggingConfiguration.kt b/src/nativeMain/kotlin/io/github/oshai/KotlinLoggingConfiguration.kt similarity index 81% rename from src/nativeMain/kotlin/mu/KotlinLoggingConfiguration.kt rename to src/nativeMain/kotlin/io/github/oshai/KotlinLoggingConfiguration.kt index ffe4e538..23c5779b 100644 --- a/src/nativeMain/kotlin/mu/KotlinLoggingConfiguration.kt +++ b/src/nativeMain/kotlin/io/github/oshai/KotlinLoggingConfiguration.kt @@ -1,4 +1,4 @@ -package mu +package io.github.oshai import kotlin.native.concurrent.AtomicReference @@ -6,8 +6,8 @@ public expect val DefaultAppender: Appender @Suppress("ObjectPropertyName") public object KotlinLoggingConfiguration { - private val _logLevel = AtomicReference(KotlinLoggingLevel.INFO) - public var logLevel: KotlinLoggingLevel + private val _logLevel = AtomicReference(io.github.oshai.Level.INFO) + public var logLevel: io.github.oshai.Level get() = _logLevel.value set(value) { _logLevel.value = value diff --git a/src/nativeMain/kotlin/io/github/oshai/KotlinLoggingLevel.kt b/src/nativeMain/kotlin/io/github/oshai/KotlinLoggingLevel.kt new file mode 100644 index 00000000..71b77748 --- /dev/null +++ b/src/nativeMain/kotlin/io/github/oshai/KotlinLoggingLevel.kt @@ -0,0 +1,5 @@ +package io.github.oshai + +import io.github.oshai.KotlinLoggingConfiguration.logLevel + +public fun io.github.oshai.Level.isLoggingEnabled(): Boolean = this.ordinal >= logLevel.ordinal diff --git a/src/nativeMain/kotlin/mu/internal/ErrorMessageProducer.kt b/src/nativeMain/kotlin/io/github/oshai/internal/ErrorMessageProducer.kt similarity index 80% rename from src/nativeMain/kotlin/mu/internal/ErrorMessageProducer.kt rename to src/nativeMain/kotlin/io/github/oshai/internal/ErrorMessageProducer.kt index 32da3fba..60fb6c9d 100644 --- a/src/nativeMain/kotlin/mu/internal/ErrorMessageProducer.kt +++ b/src/nativeMain/kotlin/io/github/oshai/internal/ErrorMessageProducer.kt @@ -1,4 +1,4 @@ -package mu.internal +package io.github.oshai.internal public actual object ErrorMessageProducer { public actual fun getErrorLog(e: Exception): String = "Log message invocation failed: $e" diff --git a/src/nativeMain/kotlin/mu/internal/KLoggerLinux.kt b/src/nativeMain/kotlin/io/github/oshai/internal/KLoggerLinux.kt similarity index 58% rename from src/nativeMain/kotlin/mu/internal/KLoggerLinux.kt rename to src/nativeMain/kotlin/io/github/oshai/internal/KLoggerLinux.kt index c28a8745..fd048e8b 100644 --- a/src/nativeMain/kotlin/mu/internal/KLoggerLinux.kt +++ b/src/nativeMain/kotlin/io/github/oshai/internal/KLoggerLinux.kt @@ -1,14 +1,14 @@ -package mu.internal +package io.github.oshai.internal -import mu.KLogger -import mu.KotlinLoggingConfiguration.appender -import mu.KotlinLoggingConfiguration.formatter -import mu.KotlinLoggingLevel -import mu.KotlinLoggingLevel.* -import mu.Marker -import mu.isLoggingEnabled +import io.github.oshai.KLogger +import io.github.oshai.KotlinLoggingConfiguration.appender +import io.github.oshai.KotlinLoggingConfiguration.formatter +import io.github.oshai.Level +import io.github.oshai.Level.* +import io.github.oshai.Marker +import io.github.oshai.isLoggingEnabled -internal class KLoggerLinux(private val loggerName: String) : KLogger { +internal class KLoggerLinux(override val name: String) : io.github.oshai.KLogger { override fun trace(msg: () -> Any?) = TRACE.logIfEnabled(msg, appender::trace) @@ -30,79 +30,73 @@ internal class KLoggerLinux(private val loggerName: String) : KLogger { override fun error(t: Throwable?, msg: () -> Any?) = ERROR.logIfEnabled(msg, t, appender::error) - override fun trace(marker: Marker?, msg: () -> Any?) = + override fun trace(marker: io.github.oshai.Marker?, msg: () -> Any?) = TRACE.logIfEnabled(marker, msg, appender::trace) - override fun debug(marker: Marker?, msg: () -> Any?) = + override fun debug(marker: io.github.oshai.Marker?, msg: () -> Any?) = DEBUG.logIfEnabled(marker, msg, appender::debug) - override fun info(marker: Marker?, msg: () -> Any?) = + override fun info(marker: io.github.oshai.Marker?, msg: () -> Any?) = INFO.logIfEnabled(marker, msg, appender::info) - override fun warn(marker: Marker?, msg: () -> Any?) = + override fun warn(marker: io.github.oshai.Marker?, msg: () -> Any?) = WARN.logIfEnabled(marker, msg, appender::warn) - override fun error(marker: Marker?, msg: () -> Any?) = + override fun error(marker: io.github.oshai.Marker?, msg: () -> Any?) = ERROR.logIfEnabled(marker, msg, appender::error) - override fun trace(marker: Marker?, t: Throwable?, msg: () -> Any?) = + override fun trace(marker: io.github.oshai.Marker?, t: Throwable?, msg: () -> Any?) = TRACE.logIfEnabled(marker, msg, t, appender::trace) - override fun debug(marker: Marker?, t: Throwable?, msg: () -> Any?) = + override fun debug(marker: io.github.oshai.Marker?, t: Throwable?, msg: () -> Any?) = DEBUG.logIfEnabled(marker, msg, t, appender::debug) - override fun info(marker: Marker?, t: Throwable?, msg: () -> Any?) = + override fun info(marker: io.github.oshai.Marker?, t: Throwable?, msg: () -> Any?) = INFO.logIfEnabled(marker, msg, t, appender::info) - override fun warn(marker: Marker?, t: Throwable?, msg: () -> Any?) = + override fun warn(marker: io.github.oshai.Marker?, t: Throwable?, msg: () -> Any?) = WARN.logIfEnabled(marker, msg, t, appender::warn) - override fun error(marker: Marker?, t: Throwable?, msg: () -> Any?) = + override fun error(marker: io.github.oshai.Marker?, t: Throwable?, msg: () -> Any?) = ERROR.logIfEnabled(marker, msg, t, appender::error) - private fun KotlinLoggingLevel.logIfEnabled( + private fun io.github.oshai.Level.logIfEnabled( msg: () -> Any?, logFunction: (String, String) -> Unit ) { if (isLoggingEnabled()) { - logFunction( - loggerName, formatter.formatMessage(appender.includePrefix, this, loggerName, msg)) + logFunction(name, formatter.formatMessage(appender.includePrefix, this, name, msg)) } } - private fun KotlinLoggingLevel.logIfEnabled( + private fun io.github.oshai.Level.logIfEnabled( msg: () -> Any?, t: Throwable?, logFunction: (String, String) -> Unit ) { if (isLoggingEnabled()) { - logFunction( - loggerName, formatter.formatMessage(appender.includePrefix, this, loggerName, t, msg)) + logFunction(name, formatter.formatMessage(appender.includePrefix, this, name, t, msg)) } } - private fun KotlinLoggingLevel.logIfEnabled( - marker: Marker?, + private fun io.github.oshai.Level.logIfEnabled( + marker: io.github.oshai.Marker?, msg: () -> Any?, logFunction: (String, String) -> Unit ) { if (isLoggingEnabled()) { - logFunction( - loggerName, - formatter.formatMessage(appender.includePrefix, this, loggerName, marker, msg)) + logFunction(name, formatter.formatMessage(appender.includePrefix, this, name, marker, msg)) } } - private fun KotlinLoggingLevel.logIfEnabled( - marker: Marker?, + private fun io.github.oshai.Level.logIfEnabled( + marker: io.github.oshai.Marker?, msg: () -> Any?, t: Throwable?, logFunction: (String, String) -> Unit ) { if (isLoggingEnabled()) { - logFunction( - loggerName, - formatter.formatMessage(appender.includePrefix, this, loggerName, marker, t, msg)) + logFunction(name, formatter.formatMessage(appender.includePrefix, this, name, marker, t, msg)) } } diff --git a/src/nativeMain/kotlin/mu/KMarkerFactory.kt b/src/nativeMain/kotlin/mu/KMarkerFactory.kt deleted file mode 100644 index f806c4d7..00000000 --- a/src/nativeMain/kotlin/mu/KMarkerFactory.kt +++ /dev/null @@ -1,8 +0,0 @@ -package mu - -import mu.internal.MarkerNative - -public actual object KMarkerFactory { - - public actual fun getMarker(name: String): Marker = MarkerNative(name) -} diff --git a/src/nativeMain/kotlin/mu/KotlinLoggingLevel.kt b/src/nativeMain/kotlin/mu/KotlinLoggingLevel.kt deleted file mode 100644 index dd21c703..00000000 --- a/src/nativeMain/kotlin/mu/KotlinLoggingLevel.kt +++ /dev/null @@ -1,13 +0,0 @@ -package mu - -import mu.KotlinLoggingConfiguration.logLevel - -public enum class KotlinLoggingLevel { - TRACE, - DEBUG, - INFO, - WARN, - ERROR -} - -public fun KotlinLoggingLevel.isLoggingEnabled(): Boolean = this.ordinal >= logLevel.ordinal diff --git a/src/nativeMain/kotlin/mu/Marker.kt b/src/nativeMain/kotlin/mu/Marker.kt deleted file mode 100644 index 87f8f10b..00000000 --- a/src/nativeMain/kotlin/mu/Marker.kt +++ /dev/null @@ -1,6 +0,0 @@ -package mu - -public actual interface Marker { - - public actual fun getName(): String -} diff --git a/src/nativeMain/kotlin/mu/internal/MarkerNative.kt b/src/nativeMain/kotlin/mu/internal/MarkerNative.kt deleted file mode 100644 index eb82e294..00000000 --- a/src/nativeMain/kotlin/mu/internal/MarkerNative.kt +++ /dev/null @@ -1,8 +0,0 @@ -package mu.internal - -import mu.Marker - -internal class MarkerNative(private val name: String) : Marker { - - override fun getName(): String = this.name -} diff --git a/src/nativeTest/kotlin/io/github/oshai/SimpleTest.kt b/src/nativeTest/kotlin/io/github/oshai/SimpleTest.kt new file mode 100644 index 00000000..5cb9a774 --- /dev/null +++ b/src/nativeTest/kotlin/io/github/oshai/SimpleTest.kt @@ -0,0 +1,9 @@ +package io.github.oshai + +class SimpleTest {} + +private val logger = io.github.oshai.KotlinLogging.logger {} + +fun main() { + logger.info { "Hello!" } +} diff --git a/src/nativeTest/kotlin/mu/SimpleTest.kt b/src/nativeTest/kotlin/mu/SimpleTest.kt deleted file mode 100644 index 4588877f..00000000 --- a/src/nativeTest/kotlin/mu/SimpleTest.kt +++ /dev/null @@ -1,9 +0,0 @@ -package mu - -class SimpleTest {} - -private val logger = KotlinLogging.logger {} - -fun main() { - logger.info { "Hello!" } -} diff --git a/versions.gradle.kts b/versions.gradle.kts index 0b8b108c..8b706a7e 100644 --- a/versions.gradle.kts +++ b/versions.gradle.kts @@ -1,4 +1,4 @@ -extra["slf4j_version"] = "2.0.3" +extra["slf4j_version"] = "2.0.6" extra["log4j_version"] = "2.19.0" extra["mockito_version"] = "4.8.0" extra["junit_version"] = "5.9.1"