diff --git a/build.gradle.kts b/build.gradle.kts index 3cae60b6..18ac1c2e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -261,7 +261,7 @@ tasks { spotless { kotlin { target("src/**/*.kt") - ktfmt("0.24").googleStyle() + ktfmt("0.47").googleStyle() } } diff --git a/src/commonMain/kotlin/io/github/oshai/kotlinlogging/KLogger.kt b/src/commonMain/kotlin/io/github/oshai/kotlinlogging/KLogger.kt index 6f0bd1f3..d07df3c9 100644 --- a/src/commonMain/kotlin/io/github/oshai/kotlinlogging/KLogger.kt +++ b/src/commonMain/kotlin/io/github/oshai/kotlinlogging/KLogger.kt @@ -14,6 +14,7 @@ public interface KLogger { /** * Return the name of this `Logger` instance. + * * @return name of this logger instance */ public val name: String @@ -378,7 +379,7 @@ public interface KLogger { */ @Deprecated( "Use trace {} instead", - replaceWith = ReplaceWith("trace(marker) { \"\$msg \$arg1 \$arg2\"}") + replaceWith = ReplaceWith("trace(marker) { \"\$msg \$arg1 \$arg2\"}"), ) public fun trace(marker: Marker?, msg: String?, arg1: Any?, arg2: Any?): Unit = TODO() @@ -392,7 +393,7 @@ public interface KLogger { */ @Deprecated( "Use trace {} instead", - replaceWith = ReplaceWith("trace(marker) { \"\$msg \$arguments\"}") + replaceWith = ReplaceWith("trace(marker) { \"\$msg \$arguments\"}"), ) public fun trace(marker: Marker?, msg: String?, vararg arguments: Any?): Unit = TODO() @@ -494,7 +495,7 @@ public interface KLogger { */ @Deprecated( "Use debug {} instead", - replaceWith = ReplaceWith("debug(marker) { \"\$msg \$arg1 \$arg2\"}") + replaceWith = ReplaceWith("debug(marker) { \"\$msg \$arg1 \$arg2\"}"), ) public fun debug(marker: Marker?, msg: String?, arg1: Any?, arg2: Any?): Unit = TODO() @@ -508,7 +509,7 @@ public interface KLogger { */ @Deprecated( "Use debug {} instead", - replaceWith = ReplaceWith("debug(marker) { \"\$msg \$arguments\"}") + replaceWith = ReplaceWith("debug(marker) { \"\$msg \$arguments\"}"), ) public fun debug(marker: Marker?, msg: String?, vararg arguments: Any?): Unit = TODO() @@ -609,7 +610,7 @@ public interface KLogger { */ @Deprecated( "Use info {} instead", - replaceWith = ReplaceWith("info(marker) { \"\$msg \$arg1 \$arg2\"}") + replaceWith = ReplaceWith("info(marker) { \"\$msg \$arg1 \$arg2\"}"), ) public fun info(marker: Marker?, msg: String?, arg1: Any?, arg2: Any?): Unit = TODO() @@ -623,7 +624,7 @@ public interface KLogger { */ @Deprecated( "Use info {} instead", - replaceWith = ReplaceWith("info(marker) { \"\$msg \$arguments\"}") + replaceWith = ReplaceWith("info(marker) { \"\$msg \$arguments\"}"), ) public fun info(marker: Marker?, msg: String?, vararg arguments: Any?): Unit = TODO() @@ -724,7 +725,7 @@ public interface KLogger { */ @Deprecated( "Use warn {} instead", - replaceWith = ReplaceWith("warn(marker) { \"\$msg \$arg1 \$arg2\"}") + replaceWith = ReplaceWith("warn(marker) { \"\$msg \$arg1 \$arg2\"}"), ) public fun warn(marker: Marker?, msg: String?, arg1: Any?, arg2: Any?): Unit = TODO() @@ -738,7 +739,7 @@ public interface KLogger { */ @Deprecated( "Use warn {} instead", - replaceWith = ReplaceWith("warn(marker) { \"\$msg \$arguments\"}") + replaceWith = ReplaceWith("warn(marker) { \"\$msg \$arguments\"}"), ) public fun warn(marker: Marker?, msg: String?, vararg arguments: Any?): Unit = TODO() @@ -817,7 +818,7 @@ public interface KLogger { */ @Deprecated( "Use error(marker){} instead", - replaceWith = ReplaceWith("error(marker) { \"\$msg\"}") + replaceWith = ReplaceWith("error(marker) { \"\$msg\"}"), ) public fun error(marker: Marker?, msg: String?): Unit = error(null as Throwable?, marker) { msg } @@ -831,7 +832,7 @@ public interface KLogger { */ @Deprecated( "Use error(marker){} instead", - replaceWith = ReplaceWith("error(marker) { \"\$msg \$arg \"}") + replaceWith = ReplaceWith("error(marker) { \"\$msg \$arg \"}"), ) public fun error(marker: Marker?, msg: String?, arg: Any?): Unit = TODO() @@ -846,7 +847,7 @@ public interface KLogger { */ @Deprecated( "Use error(marker){} instead", - replaceWith = ReplaceWith("error(marker) { \"\$msg \$arg1 \$arg2\"}") + replaceWith = ReplaceWith("error(marker) { \"\$msg \$arg1 \$arg2\"}"), ) public fun error(marker: Marker?, msg: String?, arg1: Any?, arg2: Any?): Unit = TODO() @@ -860,7 +861,7 @@ public interface KLogger { */ @Deprecated( "Use error(marker){} instead", - replaceWith = ReplaceWith("error(marker) { \"\$msg \$arguments\"}") + replaceWith = ReplaceWith("error(marker) { \"\$msg \$arguments\"}"), ) public fun error(marker: Marker?, msg: String?, vararg arguments: Any?): Unit = TODO() diff --git a/src/commonMain/kotlin/io/github/oshai/kotlinlogging/KotlinLogging.kt b/src/commonMain/kotlin/io/github/oshai/kotlinlogging/KotlinLogging.kt index c9c28236..fc350e4a 100644 --- a/src/commonMain/kotlin/io/github/oshai/kotlinlogging/KotlinLogging.kt +++ b/src/commonMain/kotlin/io/github/oshai/kotlinlogging/KotlinLogging.kt @@ -17,6 +17,7 @@ public object KotlinLogging { * ``` * private val logger = KotlinLogging.logger("io.github.oshai.kotlinlogging.MyLogger") * ``` + * * In most cases the name represents the package notation of the file that the logger is defined * in. */ diff --git a/src/darwinMain/kotlin/io/github/oshai/kotlinlogging/DarwinKLogger.kt b/src/darwinMain/kotlin/io/github/oshai/kotlinlogging/DarwinKLogger.kt index ddee780c..c9cb8f7e 100644 --- a/src/darwinMain/kotlin/io/github/oshai/kotlinlogging/DarwinKLogger.kt +++ b/src/darwinMain/kotlin/io/github/oshai/kotlinlogging/DarwinKLogger.kt @@ -35,7 +35,7 @@ public class DarwinKLogger(override val name: String, override val underlyingLog __dso_handle.ptr, underlyingLogger, level.toDarwinLevel(), - formattedMessage + formattedMessage, ) } } diff --git a/src/darwinMain/kotlin/io/github/oshai/kotlinlogging/internal/KLoggerFactory.kt b/src/darwinMain/kotlin/io/github/oshai/kotlinlogging/internal/KLoggerFactory.kt index 882dae95..f5e6533d 100644 --- a/src/darwinMain/kotlin/io/github/oshai/kotlinlogging/internal/KLoggerFactory.kt +++ b/src/darwinMain/kotlin/io/github/oshai/kotlinlogging/internal/KLoggerFactory.kt @@ -31,7 +31,7 @@ internal actual object KLoggerFactory { name.contains(".") -> { DarwinKLogger( name, - os_log_create(name.substringBeforeLast("."), name.substringAfterLast(".")) + os_log_create(name.substringBeforeLast("."), name.substringAfterLast(".")), ) } else -> { diff --git a/src/directMain/kotlin/io/github/oshai/kotlinlogging/Appender.kt b/src/directMain/kotlin/io/github/oshai/kotlinlogging/Appender.kt index 5d56b226..d467d65c 100644 --- a/src/directMain/kotlin/io/github/oshai/kotlinlogging/Appender.kt +++ b/src/directMain/kotlin/io/github/oshai/kotlinlogging/Appender.kt @@ -6,6 +6,7 @@ public interface Appender { public abstract class FormattingAppender : Appender { public abstract fun logFormattedMessage(loggingEvent: KLoggingEvent, formattedMessage: Any?) + override fun log(loggingEvent: KLoggingEvent) { KotlinLoggingConfiguration.formatter.formatMessage(loggingEvent).let { logFormattedMessage(loggingEvent, it) diff --git a/src/directMain/kotlin/io/github/oshai/kotlinlogging/KLoggingEvent.kt b/src/directMain/kotlin/io/github/oshai/kotlinlogging/KLoggingEvent.kt index a06afbfb..200beaf6 100644 --- a/src/directMain/kotlin/io/github/oshai/kotlinlogging/KLoggingEvent.kt +++ b/src/directMain/kotlin/io/github/oshai/kotlinlogging/KLoggingEvent.kt @@ -12,13 +12,13 @@ public data class KLoggingEvent( level: Level, marker: Marker?, loggerName: String, - eventBuilder: KLoggingEventBuilder + eventBuilder: KLoggingEventBuilder, ) : this( level, marker, loggerName, eventBuilder.message, eventBuilder.cause, - eventBuilder.payload + eventBuilder.payload, ) } diff --git a/src/javaMain/kotlin/io/github/oshai/kotlinlogging/internal/KLoggerNameResolver.kt b/src/javaMain/kotlin/io/github/oshai/kotlinlogging/internal/KLoggerNameResolver.kt index 162045e9..c880446f 100644 --- a/src/javaMain/kotlin/io/github/oshai/kotlinlogging/internal/KLoggerNameResolver.kt +++ b/src/javaMain/kotlin/io/github/oshai/kotlinlogging/internal/KLoggerNameResolver.kt @@ -36,7 +36,6 @@ internal actual object KLoggerNameResolver { // to search for the target declared field. null } - } - ?: clazz + } ?: clazz } } 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 b1b1e9b6..b452469f 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 @@ -37,6 +37,7 @@ internal class LocationAwareKLogger(override val underlyingLogger: LocationAware override fun isLoggingEnabledFor(level: Level, marker: Marker?): Boolean { return isLoggingEnabledFor(underlyingLogger, level, marker) } + override fun at(level: Level, marker: Marker?, block: KLoggingEventBuilder.() -> Unit) { if (isLoggingEnabledFor(level, marker)) { KLoggingEventBuilder().apply(block).run { @@ -52,7 +53,7 @@ internal class LocationAwareKLogger(override val underlyingLogger: LocationAware private fun logWithPayload( kLoggingEventBuilder: KLoggingEventBuilder, level: Level, - marker: Marker? + marker: Marker?, ) { val builder = underlyingLogger.atLevel(level.toSlf4j()) marker?.toSlf4j()?.let { builder.addMarker(it) } @@ -67,7 +68,7 @@ internal class LocationAwareKLogger(override val underlyingLogger: LocationAware private fun logWithoutPayload( kLoggingEventBuilder: KLoggingEventBuilder, level: Level, - marker: Marker? + marker: Marker?, ) { underlyingLogger.log( marker?.toSlf4j(), @@ -75,7 +76,7 @@ internal class LocationAwareKLogger(override val underlyingLogger: LocationAware level.toSlf4j().toInt(), kLoggingEventBuilder.message, null, - kLoggingEventBuilder.cause + kLoggingEventBuilder.cause, ) } @@ -158,7 +159,7 @@ internal class LocationAwareKLogger(override val underlyingLogger: LocationAware EventConstants.TRACE_INT, tp.message, arrayOf(result), - tp.throwable + tp.throwable, ) } return result diff --git a/src/javaMain/kotlin/io/github/oshai/kotlinlogging/slf4j/internal/LocationIgnorantKLogger.kt b/src/javaMain/kotlin/io/github/oshai/kotlinlogging/slf4j/internal/LocationIgnorantKLogger.kt index c1115c81..482693e5 100644 --- a/src/javaMain/kotlin/io/github/oshai/kotlinlogging/slf4j/internal/LocationIgnorantKLogger.kt +++ b/src/javaMain/kotlin/io/github/oshai/kotlinlogging/slf4j/internal/LocationIgnorantKLogger.kt @@ -38,7 +38,7 @@ internal class LocationIgnorantKLogger(override val underlyingLogger: Logger) : private fun logWithPayload( kLoggingEventBuilder: KLoggingEventBuilder, level: Level, - marker: Marker? + marker: Marker?, ) { val builder = underlyingLogger.atLevel(level.toSlf4j()) marker?.toSlf4j()?.let { builder.addMarker(it) } @@ -50,7 +50,7 @@ internal class LocationIgnorantKLogger(override val underlyingLogger: Logger) : private fun logWithoutPayload( kLoggingEventBuilder: KLoggingEventBuilder, level: Level, - marker: Marker? + marker: Marker?, ) { val slf4jMarker = marker?.toSlf4j() val message = kLoggingEventBuilder.message diff --git a/src/javaMain/kotlin/io/github/oshai/kotlinlogging/slf4j/internal/Slf4jLogger.kt b/src/javaMain/kotlin/io/github/oshai/kotlinlogging/slf4j/internal/Slf4jLogger.kt index 909fcdd5..ec6813ec 100644 --- a/src/javaMain/kotlin/io/github/oshai/kotlinlogging/slf4j/internal/Slf4jLogger.kt +++ b/src/javaMain/kotlin/io/github/oshai/kotlinlogging/slf4j/internal/Slf4jLogger.kt @@ -16,7 +16,7 @@ public abstract class Slf4jLogger : KLogger, DelegatingKLogger { protected fun isLoggingEnabledFor( underlyingLogger: Logger, level: Level, - marker: Marker? + marker: Marker?, ): Boolean { return when (level) { Level.TRACE -> underlyingLogger.isTraceEnabled(marker?.toSlf4j()) @@ -137,21 +137,21 @@ public abstract class Slf4jLogger : KLogger, DelegatingKLogger { @Deprecated( "Use error(marker){} instead", - replaceWith = ReplaceWith("error(marker){ \"\$msg \$arg\"}") + replaceWith = ReplaceWith("error(marker){ \"\$msg \$arg\"}"), ) public override fun error(marker: Marker?, msg: String?, arg: Any?): Unit = underlyingLogger.error(marker?.toSlf4j(), msg, arg) @Deprecated( "Use error(marker){} instead", - replaceWith = ReplaceWith("error(marker){ \"\$msg \$arg1 \$arg2\"}") + replaceWith = ReplaceWith("error(marker){ \"\$msg \$arg1 \$arg2\"}"), ) public override fun error(marker: Marker?, msg: String?, arg1: Any?, arg2: Any?): Unit = underlyingLogger.error(marker?.toSlf4j(), msg, arg1, arg2) @Deprecated( "Use error(marker){} instead", - replaceWith = ReplaceWith("error(marker){ \"\$msg \$arguments\"}") + replaceWith = ReplaceWith("error(marker){ \"\$msg \$arguments\"}"), ) public override fun error(marker: Marker?, msg: String?, vararg arguments: Any?): Unit = underlyingLogger.error(marker?.toSlf4j(), msg, *arguments) diff --git a/src/jsMain/kotlin/io/github/oshai/kotlinlogging/KotlinLogging.kt b/src/jsMain/kotlin/io/github/oshai/kotlinlogging/KotlinLogging.kt index 5dc7f945..8a85526c 100644 --- a/src/jsMain/kotlin/io/github/oshai/kotlinlogging/KotlinLogging.kt +++ b/src/jsMain/kotlin/io/github/oshai/kotlinlogging/KotlinLogging.kt @@ -5,6 +5,7 @@ import kotlin.reflect.KProperty /** * The JS way to define a logger without explicit name + * * ``` * class MyClass { * private val logger by KotlinLogging.logger() @@ -21,8 +22,7 @@ private class LoggerDelegate : ReadOnlyProperty { logger = thisRef.asDynamic()?.constructor?.name.unsafeCast()?.let { KotlinLogging.logger(it) - } - ?: KotlinLogging.logger("root-logger") + } ?: KotlinLogging.logger("root-logger") } return logger } diff --git a/src/jsMain/kotlin/io/github/oshai/kotlinlogging/KotlinLoggingConfiguration.kt b/src/jsMain/kotlin/io/github/oshai/kotlinlogging/KotlinLoggingConfiguration.kt index 18489c3d..86a0e3b8 100644 --- a/src/jsMain/kotlin/io/github/oshai/kotlinlogging/KotlinLoggingConfiguration.kt +++ b/src/jsMain/kotlin/io/github/oshai/kotlinlogging/KotlinLoggingConfiguration.kt @@ -11,6 +11,7 @@ public actual object KotlinLoggingConfiguration { set(value) { appender = value } + @Deprecated("Use logLevel instead", ReplaceWith("logLevel")) public var LOG_LEVEL: Level get() = logLevel diff --git a/src/jvmMain/kotlin/io/github/oshai/kotlinlogging/KotlinLoggingMDC.kt b/src/jvmMain/kotlin/io/github/oshai/kotlinlogging/KotlinLoggingMDC.kt index fec2c7e2..b6547f9a 100644 --- a/src/jvmMain/kotlin/io/github/oshai/kotlinlogging/KotlinLoggingMDC.kt +++ b/src/jvmMain/kotlin/io/github/oshai/kotlinlogging/KotlinLoggingMDC.kt @@ -18,7 +18,7 @@ import org.slf4j.MDC public inline fun withLoggingContext( pair: Pair, restorePrevious: Boolean = true, - body: () -> T + body: () -> T, ): T = if (pair.second == null) { body() @@ -44,7 +44,7 @@ public inline fun withLoggingContext( public inline fun withLoggingContext( vararg pair: Pair, restorePrevious: Boolean = true, - body: () -> T + body: () -> T, ): T { val pairForMDC = pair.filter { it.second != null } val cleanupCallbacks = @@ -81,7 +81,7 @@ public inline fun withLoggingContext( public inline fun withLoggingContext( map: Map, restorePrevious: Boolean = true, - body: () -> T + body: () -> T, ): T { val cleanupCallbacks = map.map { diff --git a/src/jvmMain/kotlin/io/github/oshai/kotlinlogging/coroutines/KotlinLoggingAsyncMDC.kt b/src/jvmMain/kotlin/io/github/oshai/kotlinlogging/coroutines/KotlinLoggingAsyncMDC.kt index 6c4561c7..609392e4 100644 --- a/src/jvmMain/kotlin/io/github/oshai/kotlinlogging/coroutines/KotlinLoggingAsyncMDC.kt +++ b/src/jvmMain/kotlin/io/github/oshai/kotlinlogging/coroutines/KotlinLoggingAsyncMDC.kt @@ -20,7 +20,7 @@ import kotlinx.coroutines.slf4j.* public suspend inline fun withLoggingContextAsync( pair: Pair, restorePrevious: Boolean = true, - crossinline body: suspend () -> T + crossinline body: suspend () -> T, ): T = withLoggingContext(pair, restorePrevious = restorePrevious) { withContext(MDCContext()) { body() } @@ -37,7 +37,7 @@ public suspend inline fun withLoggingContextAsync( public suspend inline fun withLoggingContextAsync( vararg pair: Pair, restorePrevious: Boolean = true, - crossinline body: suspend () -> T + crossinline body: suspend () -> T, ): T = withLoggingContext(*pair, restorePrevious = restorePrevious) { withContext(MDCContext()) { body() } @@ -59,7 +59,7 @@ public suspend inline fun withLoggingContextAsync( public suspend inline fun withLoggingContextAsync( map: Map, restorePrevious: Boolean = true, - crossinline body: suspend () -> T + crossinline body: suspend () -> T, ): T = withLoggingContext(map, restorePrevious = restorePrevious) { withContext(MDCContext()) { body() } diff --git a/src/jvmMain/kotlin/io/github/oshai/kotlinlogging/jul/internal/JulLoggerWrapper.kt b/src/jvmMain/kotlin/io/github/oshai/kotlinlogging/jul/internal/JulLoggerWrapper.kt index 0a849bc7..ff5875a0 100644 --- a/src/jvmMain/kotlin/io/github/oshai/kotlinlogging/jul/internal/JulLoggerWrapper.kt +++ b/src/jvmMain/kotlin/io/github/oshai/kotlinlogging/jul/internal/JulLoggerWrapper.kt @@ -16,7 +16,7 @@ internal class JulLoggerWrapper(override val underlyingLogger: Logger) : override fun at( level: io.github.oshai.kotlinlogging.Level, marker: Marker?, // marker is not supported in JUL - block: KLoggingEventBuilder.() -> Unit + block: KLoggingEventBuilder.() -> Unit, ) { if (isLoggingEnabledFor(level, null)) { KLoggingEventBuilder().apply(block).run { @@ -27,7 +27,7 @@ internal class JulLoggerWrapper(override val underlyingLogger: Logger) : override fun isLoggingEnabledFor( level: io.github.oshai.kotlinlogging.Level, - marker: Marker? + marker: Marker?, ): Boolean { return underlyingLogger.isLoggable(level.toJULLevel()) } diff --git a/src/jvmTest/kotlin/io/github/oshai/kotlinlogging/AppenderWithWriter.kt b/src/jvmTest/kotlin/io/github/oshai/kotlinlogging/AppenderWithWriter.kt index 7e41b43a..6e5c80fa 100644 --- a/src/jvmTest/kotlin/io/github/oshai/kotlinlogging/AppenderWithWriter.kt +++ b/src/jvmTest/kotlin/io/github/oshai/kotlinlogging/AppenderWithWriter.kt @@ -25,5 +25,5 @@ data class AppenderWithWriter( val pattern: String = "%-5p %c %marker - %m%n", val writer: StringWriter = StringWriter(), val appender: Appender = - WriterAppender.createAppender(newPatternLayout(pattern), null, writer, "writer", false, true) + WriterAppender.createAppender(newPatternLayout(pattern), null, writer, "writer", false, true), ) diff --git a/src/jvmTest/kotlin/io/github/oshai/kotlinlogging/KotlinLoggingTest.kt b/src/jvmTest/kotlin/io/github/oshai/kotlinlogging/KotlinLoggingTest.kt index d4d42ee5..dc051c65 100644 --- a/src/jvmTest/kotlin/io/github/oshai/kotlinlogging/KotlinLoggingTest.kt +++ b/src/jvmTest/kotlin/io/github/oshai/kotlinlogging/KotlinLoggingTest.kt @@ -30,20 +30,20 @@ class KotlinLoggingTest { { assertEquals( "io.github.oshai.kotlinlogging.ForKotlinLoggingTest", - ForKotlinLoggingTest().loggerInClass.name + ForKotlinLoggingTest().loggerInClass.name, ) }, { assertEquals( "io.github.oshai.kotlinlogging.ForKotlinLoggingTest", - ForKotlinLoggingTest.loggerInCompanion.name + ForKotlinLoggingTest.loggerInCompanion.name, ) }, { assertEquals("io.github.oshai.kotlinlogging.slf4jLogger", loggerFromSlf4j.name) }, { assertEquals( "io.github.oshai.kotlinlogging.slf4jLoggerExtension", - loggerFromSlf4jExtension.name + loggerFromSlf4jExtension.name, ) }, ) diff --git a/src/jvmTest/kotlin/io/github/oshai/kotlinlogging/LoggingWithLocationTest.kt b/src/jvmTest/kotlin/io/github/oshai/kotlinlogging/LoggingWithLocationTest.kt index 726958b8..1eaccff9 100644 --- a/src/jvmTest/kotlin/io/github/oshai/kotlinlogging/LoggingWithLocationTest.kt +++ b/src/jvmTest/kotlin/io/github/oshai/kotlinlogging/LoggingWithLocationTest.kt @@ -29,7 +29,7 @@ class LoggingWithLocationTest { ClassWithLoggingForLocationTesting().log() assertEquals( "INFO ClassWithLoggingForLocationTesting.log(8) - test", - appenderWithWriter.writer.toString().trim() + appenderWithWriter.writer.toString().trim(), ) } @@ -38,7 +38,7 @@ class LoggingWithLocationTest { ClassWithLoggingForLocationTesting().logLazy() assertEquals( "INFO ClassWithLoggingForLocationTesting.logLazy(12) - test", - appenderWithWriter.writer.toString().trim() + appenderWithWriter.writer.toString().trim(), ) } @@ -47,7 +47,7 @@ class LoggingWithLocationTest { ClassWithLoggingForLocationTesting().logFluentWithPayload() assertEquals( "INFO ClassWithLoggingForLocationTesting.logFluentWithPayload(32) - test", - appenderWithWriter.writer.toString().trim() + appenderWithWriter.writer.toString().trim(), ) } @@ -56,7 +56,7 @@ class LoggingWithLocationTest { ClassWithLoggingForLocationTesting().logNull() assertEquals( "INFO ClassWithLoggingForLocationTesting.logNull(16) - null", - appenderWithWriter.writer.toString().trim() + appenderWithWriter.writer.toString().trim(), ) } @@ -72,7 +72,7 @@ class LoggingWithLocationTest { System.lineSeparator() + "TRACE " + "ClassWithLoggingForLocationTesting.logEntry(22) - exit with ((2, 1))", - appenderWithWriter.writer.toString().trim() + appenderWithWriter.writer.toString().trim(), ) } @@ -85,7 +85,7 @@ class LoggingWithLocationTest { "INFO ClassWithLoggingForLocationTesting.logExitOpt(27) - log entry body" + System.lineSeparator() + "TRACE ClassWithLoggingForLocationTesting.logExitOpt(28) - exit with (null)", - appenderWithWriter.writer.toString().trim() + appenderWithWriter.writer.toString().trim(), ) } } diff --git a/src/jvmTest/kotlin/io/github/oshai/kotlinlogging/coroutines/KotlinLoggingAsyncMDCTest.kt b/src/jvmTest/kotlin/io/github/oshai/kotlinlogging/coroutines/KotlinLoggingAsyncMDCTest.kt index 18575438..0d9507ea 100644 --- a/src/jvmTest/kotlin/io/github/oshai/kotlinlogging/coroutines/KotlinLoggingAsyncMDCTest.kt +++ b/src/jvmTest/kotlin/io/github/oshai/kotlinlogging/coroutines/KotlinLoggingAsyncMDCTest.kt @@ -106,7 +106,7 @@ class KotlinLoggingAsyncMDCTest { "c" to "d", "e" to null, "f" to null, - restorePrevious = false + restorePrevious = false, ) { assertEquals("b", MDC.get("a")) assertEquals("d", MDC.get("c")) diff --git a/src/jvmTest/kotlin/io/github/oshai/kotlinlogging/internal/KLoggerNameResolverTest.kt b/src/jvmTest/kotlin/io/github/oshai/kotlinlogging/internal/KLoggerNameResolverTest.kt index c7b9ddac..5accfc15 100644 --- a/src/jvmTest/kotlin/io/github/oshai/kotlinlogging/internal/KLoggerNameResolverTest.kt +++ b/src/jvmTest/kotlin/io/github/oshai/kotlinlogging/internal/KLoggerNameResolverTest.kt @@ -22,18 +22,18 @@ class KLoggerNameResolverTest { Arguments.of("io.github.oshai.kotlinlogging.internal.ChildClass", ChildClass::class.java), Arguments.of( "io.github.oshai.kotlinlogging.internal.BaseClass", - BaseClass.Companion::class.java + BaseClass.Companion::class.java, ), Arguments.of( "io.github.oshai.kotlinlogging.internal.ChildClass", - ChildClass.Companion::class.java + ChildClass.Companion::class.java, ), Arguments.of("io.github.oshai.kotlinlogging.internal.Singleton", Singleton::class.java), Arguments.of("io.github.oshai.kotlinlogging.internal.MyInterface", MyInterface::class.java), Arguments.of("java.lang.Object", Any().javaClass), Arguments.of( "io.github.oshai.kotlinlogging.internal.KLoggerNameResolverTest\$testNames$1", - object {}.javaClass + object {}.javaClass, ), Arguments.of( "io.github.oshai.kotlinlogging.internal.BaseClass\$InnerClass\$Obj", @@ -51,15 +51,17 @@ class KLoggerNameResolverTest { Arguments.of("io.github.oshai.kotlinlogging.internal.Foo\$Bar2", Foo.Bar3.javaClass), Arguments.of( "io.github.oshai.kotlinlogging.internal.PrivateCompanion", - PrivateCompanion().companionClass - ) + PrivateCompanion().companionClass, + ), ) } open class BaseClass { companion object + class InnerClass { object Obj + companion object CmpObj } } @@ -75,6 +77,7 @@ interface MyInterface @Suppress("unused") class Foo { object Bar + object Bar2 val z = Bar2 @@ -86,5 +89,6 @@ class Foo { class PrivateCompanion { val companionClass: Class<*> = Companion::class.java + private companion object } diff --git a/src/jvmTest/kotlin/io/github/oshai/kotlinlogging/internal/MessageInvokerJavaTest.kt b/src/jvmTest/kotlin/io/github/oshai/kotlinlogging/internal/MessageInvokerJavaTest.kt index 72aa59cc..7e9d34ab 100644 --- a/src/jvmTest/kotlin/io/github/oshai/kotlinlogging/internal/MessageInvokerJavaTest.kt +++ b/src/jvmTest/kotlin/io/github/oshai/kotlinlogging/internal/MessageInvokerJavaTest.kt @@ -15,7 +15,7 @@ class MessageInvokerJavaTest { fun toStringSafeChecksThrowException() { assertEquals( "Log message invocation failed: java.lang.Exception: hi", - { throw Exception("hi") }.toStringSafe() + { throw Exception("hi") }.toStringSafe(), ) } diff --git a/src/jvmTest/kotlin/io/github/oshai/kotlinlogging/jul/internal/JulLoggerWrapperTest.kt b/src/jvmTest/kotlin/io/github/oshai/kotlinlogging/jul/internal/JulLoggerWrapperTest.kt index 5a66094c..322c913c 100644 --- a/src/jvmTest/kotlin/io/github/oshai/kotlinlogging/jul/internal/JulLoggerWrapperTest.kt +++ b/src/jvmTest/kotlin/io/github/oshai/kotlinlogging/jul/internal/JulLoggerWrapperTest.kt @@ -55,8 +55,7 @@ class JulLoggerWrapperTest { errorLogger.error { "simple jul error message" } appenderWithWriter.writer.flush() val lines = - appenderWithWriter - .writer + appenderWithWriter.writer .toString() .trim() .replace("\r", "\n") @@ -64,7 +63,7 @@ class JulLoggerWrapperTest { .split("\n") assertEquals( "INFO io.github.oshai.kotlinlogging.jul.internal.JulLoggerWrapperTest - simple jul info message", - lines[1] + lines[1], ) assertEquals("WARN warnLogger - simple jul warn message", lines[2]) assertEquals("ERROR errorLogger - simple jul error message", lines[3]) diff --git a/src/nativeMain/kotlin/io/github/oshai/kotlinlogging/KotlinLoggingConfiguration.kt b/src/nativeMain/kotlin/io/github/oshai/kotlinlogging/KotlinLoggingConfiguration.kt index 646980ff..4273a2dd 100644 --- a/src/nativeMain/kotlin/io/github/oshai/kotlinlogging/KotlinLoggingConfiguration.kt +++ b/src/nativeMain/kotlin/io/github/oshai/kotlinlogging/KotlinLoggingConfiguration.kt @@ -11,12 +11,14 @@ public actual object KotlinLoggingConfiguration { set(value) { _logLevel.value = value } + private val _appender = AtomicReference(DefaultAppender) public actual var appender: Appender get() = _appender.value set(value) { _appender.value = value } + private val _formatter = AtomicReference(DefaultMessageFormatter(includePrefix = true)) public actual var formatter: Formatter get() = _formatter.value