diff --git a/.editorconfig b/.editorconfig index aab17e9e..392fe661 100644 --- a/.editorconfig +++ b/.editorconfig @@ -8,7 +8,6 @@ max_line_length = 150 ; Tab indentation (no size specified) indent_style = space charset = utf-8 -indent_size = 4 [*.yml] indent_size = 2 diff --git a/src/commonMain/kotlin/io/github/oshai/kotlinlogging/KLogger.kt b/src/commonMain/kotlin/io/github/oshai/kotlinlogging/KLogger.kt index 109fba4e..6a821e46 100644 --- a/src/commonMain/kotlin/io/github/oshai/kotlinlogging/KLogger.kt +++ b/src/commonMain/kotlin/io/github/oshai/kotlinlogging/KLogger.kt @@ -109,25 +109,40 @@ public interface KLogger { } /** Lazy add a log message with throwable payload if isTraceEnabled is true */ - public fun atTrace(marker: Marker? = null, block: KLoggingEventBuilder.() -> Unit): Unit = + public fun atTrace(marker: Marker?, block: KLoggingEventBuilder.() -> Unit): Unit = at(Level.TRACE, marker, block) + /** Lazy add a log message with throwable payload if isTraceEnabled is true */ + public fun atTrace(block: KLoggingEventBuilder.() -> Unit): Unit = at(Level.TRACE, null, block) + /** Lazy add a log message with throwable payload if isDebugEnabled is true */ - public fun atDebug(marker: Marker? = null, block: KLoggingEventBuilder.() -> Unit): Unit = + public fun atDebug(marker: Marker?, block: KLoggingEventBuilder.() -> Unit): Unit = at(Level.DEBUG, marker, block) + /** Lazy add a log message with throwable payload if isDebugEnabled is true */ + public fun atDebug(block: KLoggingEventBuilder.() -> Unit): Unit = at(Level.DEBUG, null, block) + /** Lazy add a log message with throwable payload if isInfoEnabled is true */ - public fun atInfo(marker: Marker? = null, block: KLoggingEventBuilder.() -> Unit): Unit = + public fun atInfo(marker: Marker?, block: KLoggingEventBuilder.() -> Unit): Unit = at(Level.INFO, marker, block) + /** Lazy add a log message with throwable payload if isInfoEnabled is true */ + public fun atInfo(block: KLoggingEventBuilder.() -> Unit): Unit = at(Level.INFO, null, block) + /** Lazy add a log message with throwable payload if isWarnEnabled is true */ - public fun atWarn(marker: Marker? = null, block: KLoggingEventBuilder.() -> Unit): Unit = + public fun atWarn(marker: Marker?, block: KLoggingEventBuilder.() -> Unit): Unit = at(Level.WARN, marker, block) + /** Lazy add a log message with throwable payload if isWarnEnabled is true */ + public fun atWarn(block: KLoggingEventBuilder.() -> Unit): Unit = at(Level.WARN, null, block) + /** Lazy add a log message with throwable payload if isErrorEnabled is true */ - public fun atError(marker: Marker? = null, block: KLoggingEventBuilder.() -> Unit): Unit = + public fun atError(marker: Marker?, block: KLoggingEventBuilder.() -> Unit): Unit = at(Level.ERROR, marker, block) + /** Lazy add a log message with throwable payload if isErrorEnabled is true */ + public fun atError(block: KLoggingEventBuilder.() -> Unit): Unit = at(Level.ERROR, null, block) + /** Lazy add a log message if level enabled */ public fun at(level: Level, marker: Marker? = null, block: KLoggingEventBuilder.() -> Unit) diff --git a/src/javaMain/kotlin/io/github/oshai/kotlinlogging/slf4j/internal/LocationAwareKLogger.kt b/src/javaMain/kotlin/io/github/oshai/kotlinlogging/slf4j/internal/LocationAwareKLogger.kt index 3dbeec27..b1b1e9b6 100644 --- a/src/javaMain/kotlin/io/github/oshai/kotlinlogging/slf4j/internal/LocationAwareKLogger.kt +++ b/src/javaMain/kotlin/io/github/oshai/kotlinlogging/slf4j/internal/LocationAwareKLogger.kt @@ -271,15 +271,27 @@ internal class LocationAwareKLogger(override val underlyingLogger: LocationAware override fun atDebug(marker: Marker?, block: KLoggingEventBuilder.() -> Unit): Unit = at(Level.DEBUG, marker, block) + /** Lazy add a log message with throwable payload if isDebugEnabled is true */ + override fun atDebug(block: KLoggingEventBuilder.() -> Unit): Unit = at(Level.DEBUG, null, block) + /** Lazy add a log message with throwable payload if isInfoEnabled is true */ override fun atInfo(marker: Marker?, block: KLoggingEventBuilder.() -> Unit): Unit = at(Level.INFO, marker, block) + /** Lazy add a log message with throwable payload if isInfoEnabled is true */ + override fun atInfo(block: KLoggingEventBuilder.() -> Unit): Unit = at(Level.INFO, null, block) + /** Lazy add a log message with throwable payload if isWarnEnabled is true */ override fun atWarn(marker: Marker?, block: KLoggingEventBuilder.() -> Unit): Unit = at(Level.WARN, marker, block) + /** Lazy add a log message with throwable payload if isWarnEnabled is true */ + override fun atWarn(block: KLoggingEventBuilder.() -> Unit): Unit = at(Level.WARN, null, block) + /** Lazy add a log message with throwable payload if isErrorEnabled is true */ override fun atError(marker: Marker?, block: KLoggingEventBuilder.() -> Unit): Unit = at(Level.ERROR, marker, block) + + /** Lazy add a log message with throwable payload if isErrorEnabled is true */ + override fun atError(block: KLoggingEventBuilder.() -> Unit): Unit = at(Level.ERROR, null, block) } diff --git a/src/jvmTest/kotlin/io/github/oshai/kotlinlogging/ClassWithLoggingForLocationTesting.kt b/src/jvmTest/kotlin/io/github/oshai/kotlinlogging/ClassWithLoggingForLocationTesting.kt index bf9440b2..f5dc1075 100644 --- a/src/jvmTest/kotlin/io/github/oshai/kotlinlogging/ClassWithLoggingForLocationTesting.kt +++ b/src/jvmTest/kotlin/io/github/oshai/kotlinlogging/ClassWithLoggingForLocationTesting.kt @@ -27,4 +27,11 @@ class ClassWithLoggingForLocationTesting { logger.info { "log entry body" } return logger.exit(null) } + + fun logFluentWithPayload() { + logger.atInfo { + message = "test" + payload = mapOf("key" to "value") + } + } } diff --git a/src/jvmTest/kotlin/io/github/oshai/kotlinlogging/LoggingWithLocationTest.kt b/src/jvmTest/kotlin/io/github/oshai/kotlinlogging/LoggingWithLocationTest.kt index 518cf9c8..726958b8 100644 --- a/src/jvmTest/kotlin/io/github/oshai/kotlinlogging/LoggingWithLocationTest.kt +++ b/src/jvmTest/kotlin/io/github/oshai/kotlinlogging/LoggingWithLocationTest.kt @@ -42,6 +42,15 @@ class LoggingWithLocationTest { ) } + @Test + fun testFluentLoggingWithLocation() { + ClassWithLoggingForLocationTesting().logFluentWithPayload() + assertEquals( + "INFO ClassWithLoggingForLocationTesting.logFluentWithPayload(32) - test", + appenderWithWriter.writer.toString().trim() + ) + } + @Test fun testNullLoggingWithLocation() { ClassWithLoggingForLocationTesting().logNull() diff --git a/versions.gradle.kts b/versions.gradle.kts index cef1d1a3..2b1f4132 100644 --- a/versions.gradle.kts +++ b/versions.gradle.kts @@ -1,5 +1,5 @@ -extra["slf4j_version"] = "2.0.6" +extra["slf4j_version"] = "2.0.9" extra["coroutines_version"] = "1.6.4" -extra["log4j_version"] = "2.20.0" +extra["log4j_version"] = "2.22.0" extra["mockito_version"] = "4.11.0" -extra["junit_version"] = "5.9.2" \ No newline at end of file +extra["junit_version"] = "5.9.2"