From 41dcc10c39a8cdee985c803fe2a86f1c7da8f7da Mon Sep 17 00:00:00 2001 From: Erik Date: Fri, 22 Mar 2024 16:44:03 +0100 Subject: [PATCH] allow only markers being supplied --- .../kotlin/io/github/oshai/kotlinlogging/KLogger.kt | 10 +++++----- .../io/github/oshai/kotlinlogging/SimpleTest.kt | 12 ++++++++++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/commonMain/kotlin/io/github/oshai/kotlinlogging/KLogger.kt b/src/commonMain/kotlin/io/github/oshai/kotlinlogging/KLogger.kt index 6a821e46..6f0bd1f3 100644 --- a/src/commonMain/kotlin/io/github/oshai/kotlinlogging/KLogger.kt +++ b/src/commonMain/kotlin/io/github/oshai/kotlinlogging/KLogger.kt @@ -74,35 +74,35 @@ public interface KLogger { } /** Lazy add a log message if isTraceEnabled is true */ - public fun trace(throwable: Throwable?, marker: Marker?, message: () -> Any?): Unit = + public fun trace(throwable: Throwable? = null, marker: Marker?, message: () -> Any?): Unit = at(Level.TRACE, marker) { this.message = message.toStringSafe() this.cause = throwable } /** Lazy add a log message if isDebugEnabled is true */ - public fun debug(throwable: Throwable?, marker: Marker?, message: () -> Any?): Unit = + public fun debug(throwable: Throwable? = null, marker: Marker?, message: () -> Any?): Unit = at(Level.DEBUG, marker) { this.message = message.toStringSafe() this.cause = throwable } /** Lazy add a log message if isInfoEnabled is true */ - public fun info(throwable: Throwable?, marker: Marker?, message: () -> Any?): Unit = + public fun info(throwable: Throwable? = null, marker: Marker?, message: () -> Any?): Unit = at(Level.INFO, marker) { this.message = message.toStringSafe() this.cause = throwable } /** Lazy add a log message if isWarnEnabled is true */ - public fun warn(throwable: Throwable?, marker: Marker?, message: () -> Any?): Unit = + public fun warn(throwable: Throwable? = null, marker: Marker?, message: () -> Any?): Unit = at(Level.WARN, marker) { this.message = message.toStringSafe() this.cause = throwable } /** Lazy add a log message if isErrorEnabled is true */ - public fun error(throwable: Throwable?, marker: Marker?, message: () -> Any?): Unit = + public fun error(throwable: Throwable? = null, marker: Marker?, message: () -> Any?): Unit = at(Level.ERROR, marker) { this.message = message.toStringSafe() this.cause = throwable diff --git a/src/commonTest/kotlin/io/github/oshai/kotlinlogging/SimpleTest.kt b/src/commonTest/kotlin/io/github/oshai/kotlinlogging/SimpleTest.kt index 6872c152..877aafe3 100644 --- a/src/commonTest/kotlin/io/github/oshai/kotlinlogging/SimpleTest.kt +++ b/src/commonTest/kotlin/io/github/oshai/kotlinlogging/SimpleTest.kt @@ -9,4 +9,16 @@ class SimpleTest { fun simpleTest() { logger.info { "Hello!" } } + + @Test + fun shouldSupportMarkers() { + + val marker = KMarkerFactory.getMarker("someMarker") + + logger.info(marker = marker) { "info" } + logger.debug(marker = marker) { "debug" } + logger.error(marker = marker) { "error" } + logger.error(marker = marker) { "warn" } + logger.trace(marker = marker) { "trace" } + } }