diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 053b3513..7009195b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -46,7 +46,7 @@ jobs: - uses: actions/setup-java@v2 with: distribution: 'adopt' - java-version: 8 + java-version: 11 - name: Restore Gradle cache id: cache-gradle diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..7b7b8f82 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,17 @@ +# CONTRIBUTING + +Pull requests are welcome! +Before submitting a PR, it is usually better to discuss your intentions either by opening a new issue or in [slack](https://kotlinlang.slack.com/messages/kotlin-logging/). + +# Building locally + +`./gradlew clean build` + +To check formatting: + +`./gradlew ktfmtCheck` + +To fix formatting: + +`./gradlew ktfmtFormat` + diff --git a/build.gradle.kts b/build.gradle.kts index 24894b40..0c9f30cb 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -9,6 +9,7 @@ plugins { id("io.github.gradle-nexus.publish-plugin") version "1.1.0" signing id("io.gitlab.arturbosch.detekt") version "1.18.0" + id("com.ncorti.ktfmt.gradle") version "0.11.0" } @@ -37,7 +38,7 @@ kotlin { kotlinOptions { apiVersion = "1.4" languageVersion = "1.4" - jvmTarget = "1.8" + jvmTarget = "11" } } } diff --git a/src/commonMain/kotlin/mu/KLogger.kt b/src/commonMain/kotlin/mu/KLogger.kt index 9dd1ab48..40fe930e 100644 --- a/src/commonMain/kotlin/mu/KLogger.kt +++ b/src/commonMain/kotlin/mu/KLogger.kt @@ -2,129 +2,78 @@ package mu public expect interface KLogger { - /** - * Lazy add a log message if isTraceEnabled is true - */ - public fun trace(msg: () -> Any?) - - /** - * Lazy add a log message if isDebugEnabled is true - */ - public fun debug(msg: () -> Any?) - - /** - * Lazy add a log message if isInfoEnabled is true - */ - public fun info(msg: () -> Any?) - - /** - * Lazy add a log message if isWarnEnabled is true - */ - public fun warn(msg: () -> Any?) - - /** - * Lazy add a log message if isErrorEnabled is true - */ - public fun error(msg: () -> Any?) - - /** - * Lazy add a log message with throwable payload if isTraceEnabled is true - */ - public fun trace(t: Throwable?, msg: () -> Any?) - - /** - * Lazy add a log message with throwable payload if isDebugEnabled is true - */ - public fun debug(t: Throwable?, msg: () -> Any?) - - /** - * Lazy add a log message with throwable payload if isInfoEnabled is true - */ - public fun info(t: Throwable?, msg: () -> Any?) - - /** - * Lazy add a log message with throwable payload if isWarnEnabled is true - */ - public fun warn(t: Throwable?, msg: () -> Any?) - - /** - * Lazy add a log message with throwable payload if isErrorEnabled is true - */ - 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?) - - /** - * Lazy add a log message with a marker if isDebugEnabled is true - */ - public fun debug(marker: Marker?, msg: () -> Any?) - - /** - * Lazy add a log message with a marker if isInfoEnabled is true - */ - public fun info(marker: Marker?, msg: () -> Any?) - - /** - * Lazy add a log message with a marker if isWarnEnabled is true - */ - public fun warn(marker: Marker?, msg: () -> Any?) - - /** - * Lazy add a log message with a marker if isErrorEnabled is true - */ - public fun error(marker: 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?) - - /** - * Lazy add a log message with a marker and throwable payload if isDebugEnabled is true - */ - public fun debug(marker: 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?) - - /** - * Lazy add a log message with a marker and throwable payload if isWarnEnabled is true - */ - public fun warn(marker: 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?) - - /** - * Add a log message with all the supplied parameters along with method name - */ - public fun entry(vararg argArray: Any?) - - /** - * Add log message indicating exit of a method - */ - public fun exit() - - /** - * Add a log message with the return value of a method - */ - public fun exit(result: T): T where T : Any? - - /** - * Add a log message indicating an exception will be thrown along with the stack trace. - */ - public fun throwing(throwable: T): T where T : Throwable - - /** - * Add a log message indicating an exception is caught along with the stack trace. - */ - public fun catching(throwable: T) where T : Throwable + /** Lazy add a log message if isTraceEnabled is true */ + public fun trace(msg: () -> Any?) + /** Lazy add a log message if isDebugEnabled is true */ + public fun debug(msg: () -> Any?) + + /** Lazy add a log message if isInfoEnabled is true */ + public fun info(msg: () -> Any?) + + /** Lazy add a log message if isWarnEnabled is true */ + public fun warn(msg: () -> Any?) + + /** Lazy add a log message if isErrorEnabled is true */ + public fun error(msg: () -> Any?) + + /** Lazy add a log message with throwable payload if isTraceEnabled is true */ + public fun trace(t: Throwable?, msg: () -> Any?) + + /** Lazy add a log message with throwable payload if isDebugEnabled is true */ + public fun debug(t: Throwable?, msg: () -> Any?) + + /** Lazy add a log message with throwable payload if isInfoEnabled is true */ + public fun info(t: Throwable?, msg: () -> Any?) + + /** Lazy add a log message with throwable payload if isWarnEnabled is true */ + public fun warn(t: Throwable?, msg: () -> Any?) + + /** Lazy add a log message with throwable payload if isErrorEnabled is true */ + 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?) + + /** Lazy add a log message with a marker if isDebugEnabled is true */ + public fun debug(marker: Marker?, msg: () -> Any?) + + /** Lazy add a log message with a marker if isInfoEnabled is true */ + public fun info(marker: Marker?, msg: () -> Any?) + + /** Lazy add a log message with a marker if isWarnEnabled is true */ + public fun warn(marker: Marker?, msg: () -> Any?) + + /** Lazy add a log message with a marker if isErrorEnabled is true */ + public fun error(marker: 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?) + + /** Lazy add a log message with a marker and throwable payload if isDebugEnabled is true */ + public fun debug(marker: 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?) + + /** Lazy add a log message with a marker and throwable payload if isWarnEnabled is true */ + public fun warn(marker: 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?) + + /** Add a log message with all the supplied parameters along with method name */ + public fun entry(vararg argArray: Any?) + + /** Add log message indicating exit of a method */ + public fun exit() + + /** Add a log message with the return value of a method */ + public fun exit(result: T): T where T : Any? + + /** Add a log message indicating an exception will be thrown along with the stack trace. */ + public fun throwing(throwable: T): T where T : Throwable + + /** Add a log message indicating an exception is caught along with the stack trace. */ + public fun catching(throwable: T) where T : Throwable } diff --git a/src/commonMain/kotlin/mu/KMarkerFactory.kt b/src/commonMain/kotlin/mu/KMarkerFactory.kt index 3419d835..eeea2eb4 100644 --- a/src/commonMain/kotlin/mu/KMarkerFactory.kt +++ b/src/commonMain/kotlin/mu/KMarkerFactory.kt @@ -1,9 +1,7 @@ package mu -/** - * A platform independent factory to create markers. - */ +/** A platform independent factory to create markers. */ public expect object KMarkerFactory { - public fun getMarker(name: String): Marker + public fun getMarker(name: String): Marker } diff --git a/src/commonMain/kotlin/mu/KotlinLogging.kt b/src/commonMain/kotlin/mu/KotlinLogging.kt index f037ae4e..bf420039 100644 --- a/src/commonMain/kotlin/mu/KotlinLogging.kt +++ b/src/commonMain/kotlin/mu/KotlinLogging.kt @@ -1,14 +1,13 @@ package mu - public expect object KotlinLogging { - /** - * This method allow defining the logger in a file in the following way: - * ``` - * val logger = KotlinLogging.logger {} - * ``` - */ - public fun logger(func: () -> Unit): KLogger + /** + * This method allow defining the logger in a file in the following way: + * ``` + * val logger = KotlinLogging.logger {} + * ``` + */ + public fun logger(func: () -> Unit): KLogger - public fun logger(name: String): KLogger + public fun logger(name: String): KLogger } diff --git a/src/commonMain/kotlin/mu/Marker.kt b/src/commonMain/kotlin/mu/Marker.kt index 69cdc4f5..f21cfe5a 100644 --- a/src/commonMain/kotlin/mu/Marker.kt +++ b/src/commonMain/kotlin/mu/Marker.kt @@ -1,9 +1,7 @@ package mu -/** - * A platform independent marker to enrich log statements. - */ +/** A platform independent marker to enrich log statements. */ public expect interface Marker { - public fun getName(): String + public fun getName(): String } diff --git a/src/commonMain/kotlin/mu/internal/MessageInvoker.kt b/src/commonMain/kotlin/mu/internal/MessageInvoker.kt index c098c67b..6242f226 100644 --- a/src/commonMain/kotlin/mu/internal/MessageInvoker.kt +++ b/src/commonMain/kotlin/mu/internal/MessageInvoker.kt @@ -2,13 +2,13 @@ package mu.internal @Suppress("NOTHING_TO_INLINE") internal inline fun (() -> Any?).toStringSafe(): String { - return try { - invoke().toString() - } catch (e: Exception) { - ErrorMessageProducer.getErrorLog(e) - } + return try { + invoke().toString() + } catch (e: Exception) { + ErrorMessageProducer.getErrorLog(e) + } } public expect object ErrorMessageProducer { - public fun getErrorLog(e: Exception): String + public fun getErrorLog(e: Exception): String } diff --git a/src/commonTest/kotlin/mu/internal/MessageInvokerTest.kt b/src/commonTest/kotlin/mu/internal/MessageInvokerTest.kt index 718dbb33..d456fedc 100644 --- a/src/commonTest/kotlin/mu/internal/MessageInvokerTest.kt +++ b/src/commonTest/kotlin/mu/internal/MessageInvokerTest.kt @@ -3,13 +3,12 @@ package mu.internal import kotlin.test.Test import kotlin.test.assertEquals - class MessageInvokerTest { - @Test - fun toStringSafeChecks() { - assertEquals(Unit.toString(), {}.toStringSafe()) - assertEquals("null", { null }.toStringSafe()) - assertEquals("hi", { "hi" }.toStringSafe()) - } + @Test + fun toStringSafeChecks() { + assertEquals(Unit.toString(), {}.toStringSafe()) + assertEquals("null", { null }.toStringSafe()) + assertEquals("hi", { "hi" }.toStringSafe()) + } } diff --git a/src/darwinMain/kotlin/mu/OSLogAppender.kt b/src/darwinMain/kotlin/mu/OSLogAppender.kt index 84d09bb6..3e31515e 100644 --- a/src/darwinMain/kotlin/mu/OSLogAppender.kt +++ b/src/darwinMain/kotlin/mu/OSLogAppender.kt @@ -11,39 +11,38 @@ import platform.darwin._os_log_internal import platform.darwin.os_log_t import platform.darwin.os_log_type_enabled import platform.darwin.os_log_type_t -import kotlin.native.concurrent.AtomicReference -public open class OSLogAppender: Appender { - override val includePrefix: Boolean = true +public open class OSLogAppender : Appender { + override val includePrefix: Boolean = true - protected open fun logger(loggerName: String): os_log_t { - return OS_LOG_DEFAULT - } + protected open fun logger(loggerName: String): os_log_t { + return OS_LOG_DEFAULT + } - private fun log(level: os_log_type_t, loggerName: String, message: String) { - val logger = logger(loggerName) - if (os_log_type_enabled(logger, level)) { - _os_log_internal(__dso_handle.ptr, logger, level, message) - } + private fun log(level: os_log_type_t, loggerName: String, message: String) { + val logger = logger(loggerName) + if (os_log_type_enabled(logger, level)) { + _os_log_internal(__dso_handle.ptr, logger, level, message) } + } - override fun trace(loggerName: String, message: String) { - log(OS_LOG_TYPE_DEBUG, loggerName, message) - } + override fun trace(loggerName: String, message: String) { + log(OS_LOG_TYPE_DEBUG, loggerName, message) + } - override fun debug(loggerName: String, message: String) { - log(OS_LOG_TYPE_DEBUG, loggerName, message) - } + override fun debug(loggerName: String, message: String) { + log(OS_LOG_TYPE_DEBUG, loggerName, message) + } - override fun info(loggerName: String, message: String) { - log(OS_LOG_TYPE_INFO, loggerName, message) - } + override fun info(loggerName: String, message: String) { + log(OS_LOG_TYPE_INFO, loggerName, message) + } - override fun warn(loggerName: String, message: String) { - log(OS_LOG_TYPE_DEFAULT, loggerName, message) - } + override fun warn(loggerName: String, message: String) { + log(OS_LOG_TYPE_DEFAULT, loggerName, message) + } - override fun error(loggerName: String, message: String) { - log(OS_LOG_TYPE_ERROR, loggerName, message) - } + override fun error(loggerName: String, message: String) { + log(OS_LOG_TYPE_ERROR, loggerName, message) + } } diff --git a/src/darwinMain/kotlin/mu/OSLogSubsystemAppender.kt b/src/darwinMain/kotlin/mu/OSLogSubsystemAppender.kt index edff0cfc..d2fdd41e 100644 --- a/src/darwinMain/kotlin/mu/OSLogSubsystemAppender.kt +++ b/src/darwinMain/kotlin/mu/OSLogSubsystemAppender.kt @@ -1,28 +1,28 @@ package mu +import kotlin.native.concurrent.AtomicReference import platform.darwin.os_log_create import platform.darwin.os_log_t -import kotlin.native.concurrent.AtomicReference public class OSLogSubsystemAppender(public val subsystem: String) : OSLogAppender() { - override val includePrefix: Boolean = false + override val includePrefix: Boolean = false - private val logs: AtomicReference> = AtomicReference(mapOf()) + private val logs: AtomicReference> = AtomicReference(mapOf()) - override fun logger(loggerName: String): os_log_t { - var logger: os_log_t - do { - val existing = logs.value - logger = existing[loggerName] - if (logger != null) { - return logger - } + override fun logger(loggerName: String): os_log_t { + var logger: os_log_t + do { + val existing = logs.value + logger = existing[loggerName] + if (logger != null) { + return logger + } - val updated = existing.toMutableMap() - logger = os_log_create(subsystem, loggerName) - updated[loggerName] = logger - } while (!logs.compareAndSet(existing, updated)) + val updated = existing.toMutableMap() + logger = os_log_create(subsystem, loggerName) + updated[loggerName] = logger + } while (!logs.compareAndSet(existing, updated)) - return logger - } + return logger + } } diff --git a/src/jsMain/kotlin/mu/Appender.kt b/src/jsMain/kotlin/mu/Appender.kt index 02303544..3082f68a 100644 --- a/src/jsMain/kotlin/mu/Appender.kt +++ b/src/jsMain/kotlin/mu/Appender.kt @@ -1,9 +1,9 @@ package mu public interface Appender { - public fun trace(message: Any?) - public fun debug(message: Any?) - public fun info(message: Any?) - public fun warn(message: Any?) - public fun error(message: Any?) + public fun trace(message: Any?) + public fun debug(message: Any?) + public fun info(message: Any?) + public fun warn(message: Any?) + public fun error(message: Any?) } diff --git a/src/jsMain/kotlin/mu/ConsoleOutputAppender.kt b/src/jsMain/kotlin/mu/ConsoleOutputAppender.kt index df0e0dde..da6b3fe3 100644 --- a/src/jsMain/kotlin/mu/ConsoleOutputAppender.kt +++ b/src/jsMain/kotlin/mu/ConsoleOutputAppender.kt @@ -1,9 +1,9 @@ package mu public object ConsoleOutputAppender : Appender { - public override fun trace(message: Any?): Unit = console.log(message) - public override fun debug(message: Any?): Unit = console.log(message) - public override fun info(message: Any?): Unit = console.info(message) - public override fun warn(message: Any?): Unit = console.warn(message) - public override fun error(message: Any?): Unit = console.error(message) + public override fun trace(message: Any?): Unit = console.log(message) + public override fun debug(message: Any?): Unit = console.log(message) + public override fun info(message: Any?): Unit = console.info(message) + public override fun warn(message: Any?): Unit = console.warn(message) + public override fun error(message: Any?): Unit = console.error(message) } diff --git a/src/jsMain/kotlin/mu/DefaultMessageFormatter.kt b/src/jsMain/kotlin/mu/DefaultMessageFormatter.kt index bbffc36b..36556a4b 100644 --- a/src/jsMain/kotlin/mu/DefaultMessageFormatter.kt +++ b/src/jsMain/kotlin/mu/DefaultMessageFormatter.kt @@ -3,34 +3,45 @@ package mu import mu.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: KotlinLoggingLevel, + loggerName: String, + msg: () -> Any? + ): String = "${level.name}: [$loggerName] ${msg.toStringSafe()}" - public override fun formatMessage(level: KotlinLoggingLevel, loggerName: String, t: Throwable?, msg: () -> Any?): String = - "${level.name}: [$loggerName] ${msg.toStringSafe()}${t.throwableToString()}" + public override fun formatMessage( + level: KotlinLoggingLevel, + loggerName: String, + t: Throwable?, + msg: () -> Any? + ): String = "${level.name}: [$loggerName] ${msg.toStringSafe()}${t.throwableToString()}" - public override fun formatMessage(level: KotlinLoggingLevel, loggerName: String, marker: Marker?, msg: () -> Any?): String = - "${level.name}: [$loggerName] ${marker?.getName()} ${msg.toStringSafe()}" + public override fun formatMessage( + level: KotlinLoggingLevel, + loggerName: String, + marker: Marker?, + msg: () -> Any? + ): String = "${level.name}: [$loggerName] ${marker?.getName()} ${msg.toStringSafe()}" - public override fun formatMessage( - level: KotlinLoggingLevel, - loggerName: String, - marker: Marker?, - t: Throwable?, - msg: () -> Any? - ): String = - "${level.name}: [$loggerName] ${marker?.getName()} ${msg.toStringSafe()}${t.throwableToString()}" + public override fun formatMessage( + level: KotlinLoggingLevel, + loggerName: String, + marker: Marker?, + t: Throwable?, + msg: () -> Any? + ): String = + "${level.name}: [$loggerName] ${marker?.getName()} ${msg.toStringSafe()}${t.throwableToString()}" - private fun Throwable?.throwableToString(): String { - if (this == null) { - return "" - } - var msg = "" - var current = this - while (current != null && current.cause != current) { - msg += ", Caused by: '${current.message}'" - current = current.cause - } - return msg + private fun Throwable?.throwableToString(): String { + if (this == null) { + return "" } + var msg = "" + var current = this + while (current != null && current.cause != current) { + msg += ", Caused by: '${current.message}'" + current = current.cause + } + return msg + } } diff --git a/src/jsMain/kotlin/mu/Formatter.kt b/src/jsMain/kotlin/mu/Formatter.kt index 83c32c8a..b4b59cc8 100644 --- a/src/jsMain/kotlin/mu/Formatter.kt +++ b/src/jsMain/kotlin/mu/Formatter.kt @@ -1,14 +1,24 @@ 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? + 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/KLogger.kt b/src/jsMain/kotlin/mu/KLogger.kt index 366a6a07..c6a130b5 100644 --- a/src/jsMain/kotlin/mu/KLogger.kt +++ b/src/jsMain/kotlin/mu/KLogger.kt @@ -3,128 +3,78 @@ package mu @Suppress("TooManyFunctions") public actual interface KLogger { - /** - * 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 + /** 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/jsMain/kotlin/mu/KMarkerFactory.kt b/src/jsMain/kotlin/mu/KMarkerFactory.kt index 40b6b39e..45e4a769 100644 --- a/src/jsMain/kotlin/mu/KMarkerFactory.kt +++ b/src/jsMain/kotlin/mu/KMarkerFactory.kt @@ -4,5 +4,5 @@ import mu.internal.MarkerJS public actual object KMarkerFactory { - public actual fun getMarker(name: String): Marker = MarkerJS(name) + 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 index 036de9ca..16c5e544 100644 --- a/src/jsMain/kotlin/mu/KotlinLogging.kt +++ b/src/jsMain/kotlin/mu/KotlinLogging.kt @@ -2,15 +2,14 @@ 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) + /** + * 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/KotlinLoggingConfiguration.kt b/src/jsMain/kotlin/mu/KotlinLoggingConfiguration.kt index 8103048d..f269d2b8 100644 --- a/src/jsMain/kotlin/mu/KotlinLoggingConfiguration.kt +++ b/src/jsMain/kotlin/mu/KotlinLoggingConfiguration.kt @@ -1,8 +1,7 @@ package mu public object KotlinLoggingConfiguration { - public var LOG_LEVEL: KotlinLoggingLevel = KotlinLoggingLevel.INFO - public var APPENDER: Appender = ConsoleOutputAppender - public var FORMATTER: Formatter = DefaultMessageFormatter - + public var LOG_LEVEL: KotlinLoggingLevel = KotlinLoggingLevel.INFO + public var APPENDER: Appender = ConsoleOutputAppender + public var FORMATTER: Formatter = DefaultMessageFormatter } diff --git a/src/jsMain/kotlin/mu/KotlinLoggingLevel.kt b/src/jsMain/kotlin/mu/KotlinLoggingLevel.kt index 0e3bdc76..dd5ac335 100644 --- a/src/jsMain/kotlin/mu/KotlinLoggingLevel.kt +++ b/src/jsMain/kotlin/mu/KotlinLoggingLevel.kt @@ -3,12 +3,11 @@ package mu import mu.KotlinLoggingConfiguration.LOG_LEVEL public enum class KotlinLoggingLevel { - TRACE, - DEBUG, - INFO, - WARN, - ERROR + 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 index 435bfe32..87f8f10b 100644 --- a/src/jsMain/kotlin/mu/Marker.kt +++ b/src/jsMain/kotlin/mu/Marker.kt @@ -2,5 +2,5 @@ package mu public actual interface Marker { - public actual fun getName(): String + public actual fun getName(): String } diff --git a/src/jsMain/kotlin/mu/internal/ErrorMessageProducer.kt b/src/jsMain/kotlin/mu/internal/ErrorMessageProducer.kt index c7d1f5a2..32da3fba 100644 --- a/src/jsMain/kotlin/mu/internal/ErrorMessageProducer.kt +++ b/src/jsMain/kotlin/mu/internal/ErrorMessageProducer.kt @@ -1,5 +1,5 @@ package mu.internal public actual object ErrorMessageProducer { - public actual fun getErrorLog(e: Exception): String = "Log message invocation failed: $e" + 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/mu/internal/KLoggerJS.kt index 2e38e9f6..41d689fc 100644 --- a/src/jsMain/kotlin/mu/internal/KLoggerJS.kt +++ b/src/jsMain/kotlin/mu/internal/KLoggerJS.kt @@ -13,103 +13,114 @@ import mu.Marker import mu.isLoggingEnabled @Suppress("TooManyFunctions") -internal class KLoggerJS( - private val loggerName: String -) : KLogger { +internal class KLoggerJS(private val loggerName: String) : KLogger { - override fun trace(msg: () -> Any?) = TRACE.logIfEnabled(msg, APPENDER::trace) + override fun trace(msg: () -> Any?) = TRACE.logIfEnabled(msg, APPENDER::trace) - override fun debug(msg: () -> Any?) = DEBUG.logIfEnabled(msg, APPENDER::debug) + override fun debug(msg: () -> Any?) = DEBUG.logIfEnabled(msg, APPENDER::debug) - override fun info(msg: () -> Any?) = INFO.logIfEnabled(msg, APPENDER::info) + override fun info(msg: () -> Any?) = INFO.logIfEnabled(msg, APPENDER::info) - override fun warn(msg: () -> Any?) = WARN.logIfEnabled(msg, APPENDER::warn) + override fun warn(msg: () -> Any?) = WARN.logIfEnabled(msg, APPENDER::warn) - override fun error(msg: () -> Any?) = ERROR.logIfEnabled(msg, APPENDER::error) + override fun error(msg: () -> Any?) = ERROR.logIfEnabled(msg, APPENDER::error) - override fun trace(t: Throwable?, msg: () -> Any?) = TRACE.logIfEnabled(msg, t, APPENDER::trace) + override fun trace(t: Throwable?, msg: () -> Any?) = TRACE.logIfEnabled(msg, t, APPENDER::trace) - override fun debug(t: Throwable?, msg: () -> Any?) = DEBUG.logIfEnabled(msg, t, APPENDER::debug) + override fun debug(t: Throwable?, msg: () -> Any?) = DEBUG.logIfEnabled(msg, t, APPENDER::debug) - override fun info(t: Throwable?, msg: () -> Any?) = INFO.logIfEnabled(msg, t, APPENDER::info) + override fun info(t: Throwable?, msg: () -> Any?) = INFO.logIfEnabled(msg, t, APPENDER::info) - override fun warn(t: Throwable?, msg: () -> Any?) = WARN.logIfEnabled(msg, t, APPENDER::warn) + override fun warn(t: Throwable?, msg: () -> Any?) = WARN.logIfEnabled(msg, t, APPENDER::warn) - override fun error(t: Throwable?, msg: () -> Any?) = ERROR.logIfEnabled(msg, t, APPENDER::error) + override fun error(t: Throwable?, msg: () -> Any?) = ERROR.logIfEnabled(msg, t, APPENDER::error) - override fun trace(marker: Marker?, msg: () -> Any?) = TRACE.logIfEnabled(marker, msg, APPENDER::trace) + override fun trace(marker: Marker?, msg: () -> Any?) = + TRACE.logIfEnabled(marker, msg, APPENDER::trace) - override fun debug(marker: Marker?, msg: () -> Any?) = DEBUG.logIfEnabled(marker, msg, APPENDER::debug) + override fun debug(marker: Marker?, msg: () -> Any?) = + DEBUG.logIfEnabled(marker, msg, APPENDER::debug) - override fun info(marker: Marker?, msg: () -> Any?) = INFO.logIfEnabled(marker, msg, APPENDER::info) + override fun info(marker: Marker?, msg: () -> Any?) = + INFO.logIfEnabled(marker, msg, APPENDER::info) - override fun warn(marker: Marker?, msg: () -> Any?) = WARN.logIfEnabled(marker, msg, APPENDER::warn) + override fun warn(marker: Marker?, msg: () -> Any?) = + WARN.logIfEnabled(marker, msg, APPENDER::warn) - override fun error(marker: Marker?, msg: () -> Any?) = ERROR.logIfEnabled(marker, msg, APPENDER::error) + override fun error(marker: Marker?, msg: () -> Any?) = + ERROR.logIfEnabled(marker, msg, APPENDER::error) - override fun trace(marker: Marker?, t: Throwable?, msg: () -> Any?) = - TRACE.logIfEnabled(marker, msg, t, APPENDER::trace) + override fun trace(marker: Marker?, t: Throwable?, msg: () -> Any?) = + TRACE.logIfEnabled(marker, msg, t, APPENDER::trace) - override fun debug(marker: Marker?, t: Throwable?, msg: () -> Any?) = - DEBUG.logIfEnabled(marker, msg, t, APPENDER::debug) + override fun debug(marker: Marker?, t: Throwable?, msg: () -> Any?) = + DEBUG.logIfEnabled(marker, msg, t, APPENDER::debug) - override fun info(marker: Marker?, t: Throwable?, msg: () -> Any?) = - INFO.logIfEnabled(marker, msg, t, APPENDER::info) + override fun info(marker: Marker?, t: Throwable?, msg: () -> Any?) = + INFO.logIfEnabled(marker, msg, t, APPENDER::info) - override fun warn(marker: Marker?, t: Throwable?, msg: () -> Any?) = - WARN.logIfEnabled(marker, msg, t, APPENDER::warn) + override fun warn(marker: Marker?, t: Throwable?, msg: () -> Any?) = + WARN.logIfEnabled(marker, msg, t, APPENDER::warn) - override fun error(marker: Marker?, t: Throwable?, msg: () -> Any?) = - ERROR.logIfEnabled(marker, msg, t, APPENDER::error) + override fun error(marker: Marker?, t: Throwable?, msg: () -> Any?) = + ERROR.logIfEnabled(marker, msg, t, APPENDER::error) - private fun KotlinLoggingLevel.logIfEnabled(msg: () -> Any?, logFunction: (Any?) -> Unit) { - if (isLoggingEnabled()) { - logFunction(FORMATTER.formatMessage(this, loggerName, msg)) - } + private fun KotlinLoggingLevel.logIfEnabled(msg: () -> Any?, logFunction: (Any?) -> Unit) { + if (isLoggingEnabled()) { + logFunction(FORMATTER.formatMessage(this, loggerName, msg)) } - - private fun KotlinLoggingLevel.logIfEnabled(msg: () -> Any?, t: Throwable?, logFunction: (Any?) -> Unit) { - if (isLoggingEnabled()) { - logFunction(FORMATTER.formatMessage(this, loggerName, t, msg)) - } + } + + private fun KotlinLoggingLevel.logIfEnabled( + msg: () -> Any?, + t: Throwable?, + logFunction: (Any?) -> Unit + ) { + if (isLoggingEnabled()) { + logFunction(FORMATTER.formatMessage(this, loggerName, t, msg)) } - - private fun KotlinLoggingLevel.logIfEnabled(marker: Marker?, msg: () -> Any?, logFunction: (Any?) -> Unit) { - if (isLoggingEnabled()) { - logFunction(FORMATTER.formatMessage(this, loggerName, marker, msg)) - } + } + + private fun KotlinLoggingLevel.logIfEnabled( + marker: Marker?, + msg: () -> Any?, + logFunction: (Any?) -> Unit + ) { + if (isLoggingEnabled()) { + logFunction(FORMATTER.formatMessage(this, loggerName, marker, msg)) } - - private fun KotlinLoggingLevel.logIfEnabled( - marker: Marker?, - msg: () -> Any?, - t: Throwable?, - logFunction: (Any?) -> Unit - ) { - if (isLoggingEnabled()) { - logFunction(FORMATTER.formatMessage(this, loggerName, marker, t, msg)) - } + } + + private fun KotlinLoggingLevel.logIfEnabled( + marker: Marker?, + msg: () -> Any?, + t: Throwable?, + logFunction: (Any?) -> Unit + ) { + if (isLoggingEnabled()) { + logFunction(FORMATTER.formatMessage(this, loggerName, marker, t, msg)) } + } - override fun entry(vararg argArray: Any?) { - TRACE.logIfEnabled({ "entry($argArray)" }, APPENDER::trace) - } + override fun entry(vararg argArray: Any?) { + TRACE.logIfEnabled({ "entry($argArray)" }, APPENDER::trace) + } - override fun exit() { - TRACE.logIfEnabled({ "exit()" }, APPENDER::trace) - } + override fun exit() { + TRACE.logIfEnabled({ "exit()" }, APPENDER::trace) + } - override fun exit(result: T): T { - TRACE.logIfEnabled({ "exit($result)" }, APPENDER::trace) - return result - } + override fun exit(result: T): T { + TRACE.logIfEnabled({ "exit($result)" }, APPENDER::trace) + return result + } - override fun throwing(throwable: T): T { - ERROR.logIfEnabled({ "throwing($throwable" }, throwable, APPENDER::error) - return throwable - } + override fun throwing(throwable: T): T { + ERROR.logIfEnabled({ "throwing($throwable" }, throwable, APPENDER::error) + return throwable + } - override fun catching(throwable: T) { - ERROR.logIfEnabled({ "catching($throwable" }, throwable, APPENDER::error) - } + override fun catching(throwable: T) { + ERROR.logIfEnabled({ "catching($throwable" }, throwable, APPENDER::error) + } } diff --git a/src/jsMain/kotlin/mu/internal/MarkerJS.kt b/src/jsMain/kotlin/mu/internal/MarkerJS.kt index 0d6435bd..c7a945fc 100644 --- a/src/jsMain/kotlin/mu/internal/MarkerJS.kt +++ b/src/jsMain/kotlin/mu/internal/MarkerJS.kt @@ -3,5 +3,5 @@ package mu.internal import mu.Marker internal class MarkerJS(private val name: String) : Marker { - override fun getName(): String = this.name + override fun getName(): String = this.name } diff --git a/src/jvmMain/kotlin/mu/KLogger.kt b/src/jvmMain/kotlin/mu/KLogger.kt index f5e1ceb0..53519efe 100644 --- a/src/jvmMain/kotlin/mu/KLogger.kt +++ b/src/jvmMain/kotlin/mu/KLogger.kt @@ -3,142 +3,89 @@ package mu import org.slf4j.Logger /** - * An extension for [Logger] with Lazy message evaluation - * example: + * 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 + /** 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/KLogging.kt b/src/jvmMain/kotlin/mu/KLogging.kt index 862b974d..6d0b4ab0 100644 --- a/src/jvmMain/kotlin/mu/KLogging.kt +++ b/src/jvmMain/kotlin/mu/KLogging.kt @@ -3,8 +3,7 @@ package mu import mu.internal.KLoggerFactory /** - * A class with logging capabilities - * usage example: + * A class with logging capabilities usage example: * ``` * class ClassWithLogging { * companion object: KLogging() @@ -15,38 +14,26 @@ import mu.internal.KLoggerFactory * ``` */ public open class KLogging : KLoggable { - override val logger: KLogger = logger() + override val logger: KLogger = logger() } -/** - * A class with logging capabilities and explicit logger name - */ +/** 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: KLogger = logger(name) } /** - * An interface representing class with logging capabilities - * implemented using a logger - * obtain a logger with logger() method + * An interface representing class with logging capabilities implemented using a logger obtain a + * logger with logger() method */ public interface KLoggable { - /** - * The member that performs the actual logging - */ - public val logger: KLogger + /** The member that performs the actual logging */ + public val logger: KLogger - /** - * get logger for the class - */ - public fun logger(): KLogger = KLoggerFactory.logger(this) + /** get logger for the class */ + public fun logger(): KLogger = KLoggerFactory.logger(this) - /** - * get logger by explicit name - */ - public fun logger(name: String): KLogger = KLoggerFactory.logger(name) + /** get logger by explicit name */ + public fun logger(name: String): KLogger = KLoggerFactory.logger(name) } - - - diff --git a/src/jvmMain/kotlin/mu/KMarkerFactory.kt b/src/jvmMain/kotlin/mu/KMarkerFactory.kt index f1074a67..06cc9333 100644 --- a/src/jvmMain/kotlin/mu/KMarkerFactory.kt +++ b/src/jvmMain/kotlin/mu/KMarkerFactory.kt @@ -4,6 +4,5 @@ import org.slf4j.MarkerFactory public actual object KMarkerFactory { - public actual fun getMarker(name: String): Marker = MarkerFactory.getMarker(name) - + public actual fun getMarker(name: String): Marker = MarkerFactory.getMarker(name) } diff --git a/src/jvmMain/kotlin/mu/KotlinLogging.kt b/src/jvmMain/kotlin/mu/KotlinLogging.kt index a5b10754..3aa32f34 100644 --- a/src/jvmMain/kotlin/mu/KotlinLogging.kt +++ b/src/jvmMain/kotlin/mu/KotlinLogging.kt @@ -3,19 +3,19 @@ package mu import mu.internal.KLoggerFactory import org.slf4j.Logger - public actual object KotlinLogging { - /** - * This method allow defining the logger in a file in the following way: - * ``` - * val logger = KotlinLogging.logger {} - * ``` - */ - public actual fun logger(func: () -> Unit): KLogger = KLoggerFactory.logger(func) + /** + * This method allow defining the logger in a file in the following way: + * ``` + * val logger = KotlinLogging.logger {} + * ``` + */ + public actual fun logger(func: () -> Unit): KLogger = KLoggerFactory.logger(func) - public actual fun logger(name: String): KLogger = KLoggerFactory.logger(name) + public actual fun logger(name: String): KLogger = KLoggerFactory.logger(name) - public fun logger(underlyingLogger: Logger): KLogger = KLoggerFactory.wrapJLogger(underlyingLogger) + 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/mu/KotlinLoggingMDC.kt index 198b4de9..695ba843 100644 --- a/src/jvmMain/kotlin/mu/KotlinLoggingMDC.kt +++ b/src/jvmMain/kotlin/mu/KotlinLoggingMDC.kt @@ -21,16 +21,16 @@ public inline fun withLoggingContext( body: () -> T ): T = if (pair.second == null) { - body() + body() } else if (!restorePrevious) { - MDC.putCloseable(pair.first, pair.second).use { body() } + MDC.putCloseable(pair.first, pair.second).use { body() } } else { - val previousValue = MDC.get(pair.first) - try { - MDC.putCloseable(pair.first, pair.second).use { body() } - } finally { - if (previousValue != null) MDC.put(pair.first, previousValue) - } + val previousValue = MDC.get(pair.first) + try { + MDC.putCloseable(pair.first, pair.second).use { body() } + } finally { + if (previousValue != null) MDC.put(pair.first, previousValue) + } } /** @@ -46,22 +46,23 @@ public inline fun withLoggingContext( restorePrevious: Boolean = true, body: () -> T ): T { - val pairForMDC = pair.filter { it.second != null } - val cleanupCallbacks = pairForMDC.map { (mdcKey, _) -> + val pairForMDC = pair.filter { it.second != null } + val cleanupCallbacks = + pairForMDC.map { (mdcKey, _) -> val mdcValue = MDC.get(mdcKey) if (restorePrevious && mdcValue != null) { - { MDC.put(mdcKey, mdcValue) } + { MDC.put(mdcKey, mdcValue) } } else { - { MDC.remove(mdcKey) } + { MDC.remove(mdcKey) } } - } + } - try { - pairForMDC.forEach { MDC.put(it.first, it.second) } - return body() - } finally { - cleanupCallbacks.forEach { it.invoke() } - } + try { + pairForMDC.forEach { MDC.put(it.first, it.second) } + return body() + } finally { + cleanupCallbacks.forEach { it.invoke() } + } } /** @@ -82,23 +83,24 @@ public inline fun withLoggingContext( restorePrevious: Boolean = true, body: () -> T ): T { - val cleanupCallbacks = map.map { + val cleanupCallbacks = + map.map { val mdcValue = MDC.get(it.key) if (restorePrevious && mdcValue != null) { - { MDC.put(it.key, mdcValue) } + { MDC.put(it.key, mdcValue) } } else { - { MDC.remove(it.key) } + { MDC.remove(it.key) } } - } + } - try { - map.forEach { - if (it.value != null) { - MDC.put(it.key, it.value) - } - } - return body() - } finally { - cleanupCallbacks.forEach { it.invoke() } + try { + map.forEach { + if (it.value != null) { + MDC.put(it.key, it.value) + } } + return body() + } finally { + cleanupCallbacks.forEach { it.invoke() } + } } diff --git a/src/jvmMain/kotlin/mu/internal/ErrorMessageProducer.kt b/src/jvmMain/kotlin/mu/internal/ErrorMessageProducer.kt index 66efdd19..4cf1aa51 100644 --- a/src/jvmMain/kotlin/mu/internal/ErrorMessageProducer.kt +++ b/src/jvmMain/kotlin/mu/internal/ErrorMessageProducer.kt @@ -1,12 +1,11 @@ package mu.internal public actual object ErrorMessageProducer { - public actual fun getErrorLog(e: Exception): String { - if (System.getProperties().containsKey("kotlin-logging.throwOnMessageError")) { - throw e - } else { - return "Log message invocation failed: $e" - } + public actual fun getErrorLog(e: Exception): String { + if (System.getProperties().containsKey("kotlin-logging.throwOnMessageError")) { + throw e + } else { + return "Log message invocation failed: $e" } - + } } diff --git a/src/jvmMain/kotlin/mu/internal/KLoggerFactory.kt b/src/jvmMain/kotlin/mu/internal/KLoggerFactory.kt index 91e53eab..52880d0d 100644 --- a/src/jvmMain/kotlin/mu/internal/KLoggerFactory.kt +++ b/src/jvmMain/kotlin/mu/internal/KLoggerFactory.kt @@ -6,42 +6,26 @@ import org.slf4j.Logger import org.slf4j.LoggerFactory import org.slf4j.spi.LocationAwareLogger -/** - * factory methods to obtain a [Logger] - */ +/** 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 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 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 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) + /** 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/KLoggerNameResolver.kt b/src/jvmMain/kotlin/mu/internal/KLoggerNameResolver.kt index 3a3dd76d..34a8935b 100644 --- a/src/jvmMain/kotlin/mu/internal/KLoggerNameResolver.kt +++ b/src/jvmMain/kotlin/mu/internal/KLoggerNameResolver.kt @@ -2,49 +2,43 @@ package mu.internal import java.lang.reflect.Modifier - -/** - * Resolves name of java classes - */ +/** Resolves name of java classes */ @Suppress("NOTHING_TO_INLINE") internal object KLoggerNameResolver { - /** - * get class name for function by the package of the function - */ - internal inline fun name(noinline func: () -> Unit): String { - val name = func.javaClass.name - val slicedName = when { - name.contains("Kt$") -> name.substringBefore("Kt$") - name.contains("$") -> name.substringBefore("$") - else -> name + /** get class name for function by the package of the function */ + internal inline fun name(noinline func: () -> Unit): String { + val name = func.javaClass.name + val slicedName = + when { + name.contains("Kt$") -> name.substringBefore("Kt$") + name.contains("$") -> name.substringBefore("$") + else -> name } - return slicedName - } - - /** - * get class name for java class (that usually represents kotlin class) - */ - internal inline fun name(forClass: Class): String = - unwrapCompanionClass(forClass).name + return slicedName + } + /** get class name for java class (that usually represents kotlin class) */ + internal inline fun name(forClass: Class): String = + unwrapCompanionClass(forClass).name - /** - * unwrap companion class to enclosing class given a Java Class - */ - private inline fun unwrapCompanionClass(clazz: Class): Class<*> { - return clazz.enclosingClass?.let { enclosingClass -> - try { - enclosingClass.declaredFields.find { field -> - field.name == clazz.simpleName && - Modifier.isStatic(field.modifiers) && - field.type == clazz - }?.run { enclosingClass } - } catch (se: SecurityException) { - // The security manager isn't properly set up, so it won't be possible - // to search for the target declared field. - null + /** unwrap companion class to enclosing class given a Java Class */ + private inline fun unwrapCompanionClass(clazz: Class): Class<*> { + return clazz.enclosingClass?.let { enclosingClass -> + try { + enclosingClass.declaredFields + .find { field -> + field.name == clazz.simpleName && + Modifier.isStatic(field.modifiers) && + field.type == clazz } - } ?: clazz + ?.run { enclosingClass } + } catch (se: SecurityException) { + // The security manager isn't properly set up, so it won't be possible + // to search for the target declared field. + null + } } + ?: clazz + } } diff --git a/src/jvmMain/kotlin/mu/internal/LocationAwareKLogger.kt b/src/jvmMain/kotlin/mu/internal/LocationAwareKLogger.kt index 3e74ecbc..6280be6e 100644 --- a/src/jvmMain/kotlin/mu/internal/LocationAwareKLogger.kt +++ b/src/jvmMain/kotlin/mu/internal/LocationAwareKLogger.kt @@ -8,590 +8,451 @@ import org.slf4j.helpers.MessageFormatter import org.slf4j.spi.LocationAwareLogger /** - * A class wrapping a [LocationAwareLogger] instance preserving - * location information with the correct fully qualified class name. + * A class wrapping a [LocationAwareLogger] instance preserving location information with the + * correct fully qualified class name. */ @Suppress("VariableNaming", "TooManyFunctions") -internal class LocationAwareKLogger(override val underlyingLogger: LocationAwareLogger) : KLogger, - Logger by underlyingLogger { +internal class LocationAwareKLogger(override val underlyingLogger: LocationAwareLogger) : + 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 fqcn: String = LocationAwareKLogger::class.java.name + private val ENTRY = KMarkerFactory.getMarker("ENTRY") + private val EXIT = KMarkerFactory.getMarker("EXIT") - private val THROWING = KMarkerFactory.getMarker("THROWING") - private val CATCHING = KMarkerFactory.getMarker("CATCHING") - private val EXITONLY = "exit" - private val EXITMESSAGE = "exit with ({})" + private val THROWING = KMarkerFactory.getMarker("THROWING") + private val CATCHING = KMarkerFactory.getMarker("CATCHING") + private val EXITONLY = "exit" + private val EXITMESSAGE = "exit with ({})" - override fun trace(msg: String?) { - if (!underlyingLogger.isTraceEnabled) return + override fun trace(msg: String?) { + if (!underlyingLogger.isTraceEnabled) return - underlyingLogger.log( - null, fqcn, LocationAwareLogger.TRACE_INT, msg, null, null - ) - } - - override fun trace(msg: String?, arg: Any?) { - if (!underlyingLogger.isTraceEnabled) return - - underlyingLogger.log( - null, fqcn, LocationAwareLogger.TRACE_INT, msg, arrayOf(arg), null - ) - } - - override fun trace(msg: String?, arg1: Any?, arg2: Any?) { - if (!underlyingLogger.isTraceEnabled) return - - underlyingLogger.log( - null, fqcn, LocationAwareLogger.TRACE_INT, msg, arrayOf(arg1, arg2), null - ) - } - - override fun trace(msg: String?, argArray: Array) { - if (!underlyingLogger.isTraceEnabled) return - - underlyingLogger.log( - null, fqcn, LocationAwareLogger.TRACE_INT, msg, argArray, null - ) - } - - override fun trace(msg: String?, t: Throwable?) { - if (!underlyingLogger.isTraceEnabled) return - - underlyingLogger.log( - null, fqcn, LocationAwareLogger.TRACE_INT, msg, null, t - ) - } - - override fun trace(marker: Marker?, msg: String?) { - if (!underlyingLogger.isTraceEnabled) return - underlyingLogger.log( - marker, fqcn, LocationAwareLogger.TRACE_INT, msg, null, null - ) - } - - override fun trace(marker: Marker?, msg: String?, arg: Any?) { - if (!underlyingLogger.isTraceEnabled) return - - underlyingLogger.log( - marker, fqcn, LocationAwareLogger.TRACE_INT, msg, arrayOf(arg), null - ) - } - - override fun trace(marker: Marker?, msg: String?, arg1: Any?, arg2: Any?) { - if (!underlyingLogger.isTraceEnabled) return - - underlyingLogger.log( - marker, fqcn, LocationAwareLogger.TRACE_INT, msg, arrayOf(arg1, arg2), null - ) - } - - override fun trace(marker: Marker?, msg: String?, argArray: Array) { - if (!underlyingLogger.isTraceEnabled) return - - underlyingLogger.log( - marker, fqcn, LocationAwareLogger.TRACE_INT, msg, argArray, null - ) - } - - override fun trace(marker: Marker?, msg: String?, t: Throwable?) { - if (!underlyingLogger.isTraceEnabled) return - underlyingLogger.log( - marker, fqcn, LocationAwareLogger.TRACE_INT, msg, null, t - ) - } + underlyingLogger.log(null, fqcn, LocationAwareLogger.TRACE_INT, msg, null, null) + } - override fun debug(msg: String?) { - if (!underlyingLogger.isDebugEnabled) return + override fun trace(msg: String?, arg: Any?) { + if (!underlyingLogger.isTraceEnabled) return - underlyingLogger.log( - null, fqcn, LocationAwareLogger.DEBUG_INT, msg, null, null - ) - } + underlyingLogger.log(null, fqcn, LocationAwareLogger.TRACE_INT, msg, arrayOf(arg), null) + } - override fun debug(msg: String?, arg: Any?) { - if (!underlyingLogger.isDebugEnabled) return + override fun trace(msg: String?, arg1: Any?, arg2: Any?) { + if (!underlyingLogger.isTraceEnabled) return - underlyingLogger.log( - null, fqcn, LocationAwareLogger.DEBUG_INT, msg, arrayOf(arg), null - ) - } + underlyingLogger.log(null, fqcn, LocationAwareLogger.TRACE_INT, msg, arrayOf(arg1, arg2), null) + } - override fun debug(msg: String?, arg1: Any?, arg2: Any?) { - if (!underlyingLogger.isDebugEnabled) return + override fun trace(msg: String?, argArray: Array) { + if (!underlyingLogger.isTraceEnabled) return - underlyingLogger.log( - null, fqcn, LocationAwareLogger.DEBUG_INT, msg, arrayOf(arg1, arg2), null - ) - } + underlyingLogger.log(null, fqcn, LocationAwareLogger.TRACE_INT, msg, argArray, null) + } - override fun debug(msg: String?, argArray: Array) { - if (!underlyingLogger.isDebugEnabled) return + override fun trace(msg: String?, t: Throwable?) { + if (!underlyingLogger.isTraceEnabled) return - underlyingLogger.log( - null, fqcn, LocationAwareLogger.DEBUG_INT, msg, argArray, null - ) - } + underlyingLogger.log(null, fqcn, LocationAwareLogger.TRACE_INT, msg, null, t) + } - override fun debug(msg: String?, t: Throwable?) { - if (!underlyingLogger.isDebugEnabled) return + override fun trace(marker: Marker?, msg: String?) { + if (!underlyingLogger.isTraceEnabled) return + underlyingLogger.log(marker, fqcn, LocationAwareLogger.TRACE_INT, msg, null, null) + } - underlyingLogger.log( - null, fqcn, LocationAwareLogger.DEBUG_INT, msg, null, t - ) - } + override fun trace(marker: Marker?, msg: String?, arg: Any?) { + if (!underlyingLogger.isTraceEnabled) return - override fun debug(marker: Marker?, msg: String?) { - if (!underlyingLogger.isDebugEnabled) return - underlyingLogger.log( - marker, fqcn, LocationAwareLogger.DEBUG_INT, msg, null, null - ) - } + underlyingLogger.log(marker, fqcn, LocationAwareLogger.TRACE_INT, msg, arrayOf(arg), null) + } - override fun debug(marker: Marker?, msg: String?, arg: Any?) { - if (!underlyingLogger.isDebugEnabled) return + override fun trace(marker: Marker?, msg: String?, arg1: Any?, arg2: Any?) { + if (!underlyingLogger.isTraceEnabled) return - underlyingLogger.log( - marker, fqcn, LocationAwareLogger.DEBUG_INT, msg, arrayOf(arg), null - ) - } - - override fun debug(marker: Marker?, arg: String?, arg1: Any?, arg2: Any?) { - if (!underlyingLogger.isDebugEnabled) return + underlyingLogger.log( + marker, fqcn, LocationAwareLogger.TRACE_INT, msg, arrayOf(arg1, arg2), null) + } - underlyingLogger.log( - marker, fqcn, LocationAwareLogger.DEBUG_INT, arg, arrayOf(arg1, arg2), null - ) - } + override fun trace(marker: Marker?, msg: String?, argArray: Array) { + if (!underlyingLogger.isTraceEnabled) return - override fun debug(marker: Marker?, arg: String?, argArray: Array) { - if (!underlyingLogger.isDebugEnabled) return + underlyingLogger.log(marker, fqcn, LocationAwareLogger.TRACE_INT, msg, argArray, null) + } - underlyingLogger.log( - marker, fqcn, LocationAwareLogger.DEBUG_INT, arg, argArray, null - ) - } + override fun trace(marker: Marker?, msg: String?, t: Throwable?) { + if (!underlyingLogger.isTraceEnabled) return + underlyingLogger.log(marker, fqcn, LocationAwareLogger.TRACE_INT, msg, null, t) + } - override fun debug(marker: Marker?, msg: String?, t: Throwable?) { - if (!underlyingLogger.isDebugEnabled) return - underlyingLogger.log( - marker, fqcn, LocationAwareLogger.DEBUG_INT, msg, null, t - ) - } + override fun debug(msg: String?) { + if (!underlyingLogger.isDebugEnabled) return - override fun info(msg: String?) { - if (!underlyingLogger.isInfoEnabled) return + underlyingLogger.log(null, fqcn, LocationAwareLogger.DEBUG_INT, msg, null, null) + } - underlyingLogger.log( - null, fqcn, LocationAwareLogger.INFO_INT, msg, null, null - ) - } + override fun debug(msg: String?, arg: Any?) { + if (!underlyingLogger.isDebugEnabled) return - override fun info(msg: String?, arg: Any?) { - if (!underlyingLogger.isInfoEnabled) return + underlyingLogger.log(null, fqcn, LocationAwareLogger.DEBUG_INT, msg, arrayOf(arg), null) + } - underlyingLogger.log( - null, fqcn, LocationAwareLogger.INFO_INT, msg, arrayOf(arg), null - ) - } - - override fun info(msg: String?, arg1: Any?, arg2: Any?) { - if (!underlyingLogger.isInfoEnabled) return - - underlyingLogger.log( - null, fqcn, LocationAwareLogger.INFO_INT, msg, arrayOf(arg1, arg2), null - ) - } - - override fun info(msg: String?, argArray: Array) { - if (!underlyingLogger.isInfoEnabled) return - - underlyingLogger.log( - null, fqcn, LocationAwareLogger.INFO_INT, msg, argArray, null - ) - } - - override fun info(msg: String?, t: Throwable?) { - if (!underlyingLogger.isInfoEnabled) return - - underlyingLogger.log( - null, fqcn, LocationAwareLogger.INFO_INT, msg, null, t - ) - } - - override fun info(marker: Marker?, msg: String?) { - if (!underlyingLogger.isInfoEnabled) return - underlyingLogger.log( - marker, fqcn, LocationAwareLogger.INFO_INT, msg, null, null - ) - } + override fun debug(msg: String?, arg1: Any?, arg2: Any?) { + if (!underlyingLogger.isDebugEnabled) return - override fun info(marker: Marker?, msg: String?, arg: Any?) { - if (!underlyingLogger.isInfoEnabled) return - underlyingLogger.log( - marker, fqcn, LocationAwareLogger.INFO_INT, msg, arrayOf(arg), null - ) - } + underlyingLogger.log(null, fqcn, LocationAwareLogger.DEBUG_INT, msg, arrayOf(arg1, arg2), null) + } - override fun info(marker: Marker?, msg: String?, arg1: Any?, arg2: Any?) { - if (!underlyingLogger.isInfoEnabled) return - underlyingLogger.log( - marker, fqcn, LocationAwareLogger.INFO_INT, msg, arrayOf(arg1, arg2), null - ) - } + override fun debug(msg: String?, argArray: Array) { + if (!underlyingLogger.isDebugEnabled) return - override fun info(marker: Marker?, msg: String?, argArray: Array) { - if (!underlyingLogger.isInfoEnabled) return - underlyingLogger.log( - marker, fqcn, LocationAwareLogger.INFO_INT, msg, argArray, null - ) - } + underlyingLogger.log(null, fqcn, LocationAwareLogger.DEBUG_INT, msg, argArray, null) + } - override fun info(marker: Marker?, msg: String?, t: Throwable?) { - if (!underlyingLogger.isInfoEnabled) return - underlyingLogger.log( - marker, fqcn, LocationAwareLogger.INFO_INT, msg, null, t - ) - } + override fun debug(msg: String?, t: Throwable?) { + if (!underlyingLogger.isDebugEnabled) return - override fun warn(msg: String?) { - if (!underlyingLogger.isWarnEnabled) return + underlyingLogger.log(null, fqcn, LocationAwareLogger.DEBUG_INT, msg, null, t) + } - underlyingLogger.log( - null, fqcn, LocationAwareLogger.WARN_INT, msg, null, null - ) - } + override fun debug(marker: Marker?, msg: String?) { + if (!underlyingLogger.isDebugEnabled) return + underlyingLogger.log(marker, fqcn, LocationAwareLogger.DEBUG_INT, msg, null, null) + } - override fun warn(msg: String?, arg: Any?) { - if (!underlyingLogger.isWarnEnabled) return + override fun debug(marker: Marker?, msg: String?, arg: Any?) { + if (!underlyingLogger.isDebugEnabled) return - underlyingLogger.log( - null, fqcn, LocationAwareLogger.WARN_INT, msg, arrayOf(arg), null - ) - } + underlyingLogger.log(marker, fqcn, LocationAwareLogger.DEBUG_INT, msg, arrayOf(arg), null) + } - override fun warn(msg: String?, arg1: Any?, arg2: Any?) { - if (!underlyingLogger.isWarnEnabled) return + override fun debug(marker: Marker?, arg: String?, arg1: Any?, arg2: Any?) { + if (!underlyingLogger.isDebugEnabled) return - underlyingLogger.log( - null, fqcn, LocationAwareLogger.WARN_INT, msg, arrayOf(arg1, arg2), null - ) - } + underlyingLogger.log( + marker, fqcn, LocationAwareLogger.DEBUG_INT, arg, arrayOf(arg1, arg2), null) + } - override fun warn(msg: String?, argArray: Array) { - if (!underlyingLogger.isWarnEnabled) return + override fun debug(marker: Marker?, arg: String?, argArray: Array) { + if (!underlyingLogger.isDebugEnabled) return - underlyingLogger.log( - null, fqcn, LocationAwareLogger.WARN_INT, msg, argArray, null - ) - } + underlyingLogger.log(marker, fqcn, LocationAwareLogger.DEBUG_INT, arg, argArray, null) + } - override fun warn(msg: String?, t: Throwable?) { - if (!underlyingLogger.isWarnEnabled) return + override fun debug(marker: Marker?, msg: String?, t: Throwable?) { + if (!underlyingLogger.isDebugEnabled) return + underlyingLogger.log(marker, fqcn, LocationAwareLogger.DEBUG_INT, msg, null, t) + } - underlyingLogger.log( - null, fqcn, LocationAwareLogger.WARN_INT, msg, null, t - ) - } + override fun info(msg: String?) { + if (!underlyingLogger.isInfoEnabled) return - override fun warn(marker: Marker?, msg: String?) { - if (!underlyingLogger.isWarnEnabled) return - underlyingLogger.log( - marker, fqcn, LocationAwareLogger.WARN_INT, msg, null, null - ) - } + underlyingLogger.log(null, fqcn, LocationAwareLogger.INFO_INT, msg, null, null) + } - override fun warn(marker: Marker?, msg: String?, arg: Any?) { - if (!underlyingLogger.isWarnEnabled) return + override fun info(msg: String?, arg: Any?) { + if (!underlyingLogger.isInfoEnabled) return - underlyingLogger.log( - marker, fqcn, LocationAwareLogger.WARN_INT, msg, arrayOf(arg), null - ) - } + underlyingLogger.log(null, fqcn, LocationAwareLogger.INFO_INT, msg, arrayOf(arg), null) + } - override fun warn(marker: Marker?, msg: String?, arg1: Any?, arg2: Any?) { - if (!underlyingLogger.isWarnEnabled) return + override fun info(msg: String?, arg1: Any?, arg2: Any?) { + if (!underlyingLogger.isInfoEnabled) return - underlyingLogger.log( - marker, fqcn, LocationAwareLogger.WARN_INT, msg, arrayOf(arg1, arg2), null - ) - } + underlyingLogger.log(null, fqcn, LocationAwareLogger.INFO_INT, msg, arrayOf(arg1, arg2), null) + } - override fun warn(marker: Marker?, msg: String?, argArray: Array) { - if (!underlyingLogger.isWarnEnabled) return + override fun info(msg: String?, argArray: Array) { + if (!underlyingLogger.isInfoEnabled) return - underlyingLogger.log( - marker, fqcn, LocationAwareLogger.WARN_INT, msg, argArray, null - ) - } + underlyingLogger.log(null, fqcn, LocationAwareLogger.INFO_INT, msg, argArray, null) + } - override fun warn(marker: Marker?, msg: String?, t: Throwable?) { - if (!underlyingLogger.isWarnEnabled) return - underlyingLogger.log( - marker, fqcn, LocationAwareLogger.WARN_INT, msg, null, t - ) - } + override fun info(msg: String?, t: Throwable?) { + if (!underlyingLogger.isInfoEnabled) return - override fun error(msg: String?) { - if (!underlyingLogger.isErrorEnabled) return + underlyingLogger.log(null, fqcn, LocationAwareLogger.INFO_INT, msg, null, t) + } - underlyingLogger.log( - null, fqcn, LocationAwareLogger.ERROR_INT, msg, null, null - ) - } + override fun info(marker: Marker?, msg: String?) { + if (!underlyingLogger.isInfoEnabled) return + underlyingLogger.log(marker, fqcn, LocationAwareLogger.INFO_INT, msg, null, null) + } - override fun error(msg: String?, arg: Any?) { - if (!underlyingLogger.isErrorEnabled) return + override fun info(marker: Marker?, msg: String?, arg: Any?) { + if (!underlyingLogger.isInfoEnabled) return + underlyingLogger.log(marker, fqcn, LocationAwareLogger.INFO_INT, msg, arrayOf(arg), null) + } - underlyingLogger.log( - null, fqcn, LocationAwareLogger.ERROR_INT, msg, arrayOf(arg), null - ) - } + override fun info(marker: Marker?, msg: String?, arg1: Any?, arg2: Any?) { + if (!underlyingLogger.isInfoEnabled) return + underlyingLogger.log(marker, fqcn, LocationAwareLogger.INFO_INT, msg, arrayOf(arg1, arg2), null) + } - override fun error(msg: String?, arg1: Any?, arg2: Any?) { - if (!underlyingLogger.isErrorEnabled) return + override fun info(marker: Marker?, msg: String?, argArray: Array) { + if (!underlyingLogger.isInfoEnabled) return + underlyingLogger.log(marker, fqcn, LocationAwareLogger.INFO_INT, msg, argArray, null) + } - underlyingLogger.log( - null, fqcn, LocationAwareLogger.ERROR_INT, msg, arrayOf(arg1, arg2), null - ) - } + override fun info(marker: Marker?, msg: String?, t: Throwable?) { + if (!underlyingLogger.isInfoEnabled) return + underlyingLogger.log(marker, fqcn, LocationAwareLogger.INFO_INT, msg, null, t) + } - override fun error(msg: String?, argArray: Array) { - if (!underlyingLogger.isErrorEnabled) return + override fun warn(msg: String?) { + if (!underlyingLogger.isWarnEnabled) return - underlyingLogger.log( - null, fqcn, LocationAwareLogger.ERROR_INT, msg, argArray, null - ) - } + underlyingLogger.log(null, fqcn, LocationAwareLogger.WARN_INT, msg, null, null) + } - override fun error(msg: String?, t: Throwable?) { - if (!underlyingLogger.isErrorEnabled) return + override fun warn(msg: String?, arg: Any?) { + if (!underlyingLogger.isWarnEnabled) return - underlyingLogger.log( - null, fqcn, LocationAwareLogger.ERROR_INT, msg, null, t - ) - } + underlyingLogger.log(null, fqcn, LocationAwareLogger.WARN_INT, msg, arrayOf(arg), null) + } - override fun error(marker: Marker?, msg: String?) { - if (!underlyingLogger.isErrorEnabled) return - underlyingLogger.log( - marker, fqcn, LocationAwareLogger.ERROR_INT, msg, null, null - ) - } + override fun warn(msg: String?, arg1: Any?, arg2: Any?) { + if (!underlyingLogger.isWarnEnabled) return - override fun error(marker: Marker?, msg: String?, arg: Any?) { - if (!underlyingLogger.isErrorEnabled) return - underlyingLogger.log( - marker, fqcn, LocationAwareLogger.ERROR_INT, msg, arrayOf(arg), null - ) - } + underlyingLogger.log(null, fqcn, LocationAwareLogger.WARN_INT, msg, arrayOf(arg1, arg2), null) + } - override fun error(marker: Marker?, msg: String?, arg1: Any?, arg2: Any?) { - if (!underlyingLogger.isErrorEnabled) return + override fun warn(msg: String?, argArray: Array) { + if (!underlyingLogger.isWarnEnabled) return - underlyingLogger.log( - marker, fqcn, LocationAwareLogger.ERROR_INT, msg, arrayOf(arg1, arg2), null - ) - } + underlyingLogger.log(null, fqcn, LocationAwareLogger.WARN_INT, msg, argArray, null) + } - override fun error(marker: Marker?, msg: String?, argArray: Array) { - if (!underlyingLogger.isErrorEnabled) return + override fun warn(msg: String?, t: Throwable?) { + if (!underlyingLogger.isWarnEnabled) return - underlyingLogger.log( - marker, fqcn, LocationAwareLogger.ERROR_INT, msg, argArray, null - ) - } + underlyingLogger.log(null, fqcn, LocationAwareLogger.WARN_INT, msg, null, t) + } - override fun error(marker: Marker?, msg: String?, t: Throwable?) { - if (!underlyingLogger.isErrorEnabled) return - underlyingLogger.log( - marker, fqcn, LocationAwareLogger.ERROR_INT, msg, null, t - ) - } + override fun warn(marker: Marker?, msg: String?) { + if (!underlyingLogger.isWarnEnabled) return + underlyingLogger.log(marker, fqcn, LocationAwareLogger.WARN_INT, msg, null, null) + } - /** - * Lazy add a log message if isTraceEnabled is true - */ - override fun trace(msg: () -> Any?) { - if (isTraceEnabled) trace(msg.toStringSafe()) - } + override fun warn(marker: Marker?, msg: String?, arg: Any?) { + if (!underlyingLogger.isWarnEnabled) return - /** - * Lazy add a log message if isDebugEnabled is true - */ - override fun debug(msg: () -> Any?) { - if (isDebugEnabled) debug(msg.toStringSafe()) - } + underlyingLogger.log(marker, fqcn, LocationAwareLogger.WARN_INT, msg, arrayOf(arg), null) + } - /** - * Lazy add a log message if isInfoEnabled is true - */ - override fun info(msg: () -> Any?) { - if (isInfoEnabled) info(msg.toStringSafe()) - } + override fun warn(marker: Marker?, msg: String?, arg1: Any?, arg2: Any?) { + if (!underlyingLogger.isWarnEnabled) return - /** - * Lazy add a log message if isWarnEnabled is true - */ - override fun warn(msg: () -> Any?) { - if (isWarnEnabled) warn(msg.toStringSafe()) - } + underlyingLogger.log(marker, fqcn, LocationAwareLogger.WARN_INT, msg, arrayOf(arg1, arg2), null) + } - /** - * Lazy add a log message if isErrorEnabled is true - */ - override fun error(msg: () -> Any?) { - if (isErrorEnabled) error(msg.toStringSafe()) - } + override fun warn(marker: Marker?, msg: String?, argArray: Array) { + if (!underlyingLogger.isWarnEnabled) return - /** - * 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) - } + underlyingLogger.log(marker, fqcn, LocationAwareLogger.WARN_INT, msg, argArray, null) + } - /** - * 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) - } + override fun warn(marker: Marker?, msg: String?, t: Throwable?) { + if (!underlyingLogger.isWarnEnabled) return + underlyingLogger.log(marker, fqcn, LocationAwareLogger.WARN_INT, msg, null, 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) - } + override fun error(msg: String?) { + if (!underlyingLogger.isErrorEnabled) return - /** - * 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) - } + underlyingLogger.log(null, fqcn, LocationAwareLogger.ERROR_INT, msg, null, null) + } - /** - * 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) - } + override fun error(msg: String?, arg: Any?) { + if (!underlyingLogger.isErrorEnabled) return - /** - * 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()) - } + underlyingLogger.log(null, fqcn, LocationAwareLogger.ERROR_INT, msg, arrayOf(arg), null) + } - /** - * 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()) - } + override fun error(msg: String?, arg1: Any?, arg2: Any?) { + if (!underlyingLogger.isErrorEnabled) return - /** - * 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()) - } + underlyingLogger.log(null, fqcn, LocationAwareLogger.ERROR_INT, msg, arrayOf(arg1, arg2), null) + } - /** - * 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()) - } + override fun error(msg: String?, argArray: Array) { + if (!underlyingLogger.isErrorEnabled) return - /** - * 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()) - } + underlyingLogger.log(null, fqcn, LocationAwareLogger.ERROR_INT, msg, argArray, null) + } - /** - * 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 error(msg: String?, t: Throwable?) { + if (!underlyingLogger.isErrorEnabled) return - /** - * 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) - } + underlyingLogger.log(null, fqcn, LocationAwareLogger.ERROR_INT, msg, null, 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 error(marker: Marker?, msg: String?) { + if (!underlyingLogger.isErrorEnabled) return + underlyingLogger.log(marker, fqcn, LocationAwareLogger.ERROR_INT, msg, null, null) + } - /** - * 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 error(marker: Marker?, msg: String?, arg: Any?) { + if (!underlyingLogger.isErrorEnabled) return + underlyingLogger.log(marker, fqcn, LocationAwareLogger.ERROR_INT, msg, arrayOf(arg), null) + } - /** - * 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(marker: Marker?, msg: String?, arg1: Any?, arg2: Any?) { + if (!underlyingLogger.isErrorEnabled) return - override fun catching(throwable: T) { - if (underlyingLogger.isErrorEnabled) { - underlyingLogger.log(CATCHING, fqcn, LocationAwareLogger.ERROR_INT, "catching", null, throwable) - } - } + underlyingLogger.log( + marker, fqcn, LocationAwareLogger.ERROR_INT, msg, arrayOf(arg1, arg2), null) + } - override fun entry(vararg argArray: Any?) { - if (underlyingLogger.isTraceEnabled(ENTRY)) { - val tp = MessageFormatter.arrayFormat(buildMessagePattern(argArray.size), argArray) - underlyingLogger.log(ENTRY, fqcn, LocationAwareLogger.TRACE_INT, tp.message, null, null) - } - } + override fun error(marker: Marker?, msg: String?, argArray: Array) { + if (!underlyingLogger.isErrorEnabled) return - override fun exit() { - if (underlyingLogger.isTraceEnabled(EXIT)) { - underlyingLogger.log(EXIT, fqcn, LocationAwareLogger.TRACE_INT, EXITONLY, null, null) - } - } + underlyingLogger.log(marker, fqcn, LocationAwareLogger.ERROR_INT, msg, argArray, null) + } - override fun exit(result: T): T { - if (underlyingLogger.isTraceEnabled(EXIT)) { - val tp = MessageFormatter.format(EXITMESSAGE, result) - underlyingLogger.log( - EXIT, fqcn, LocationAwareLogger.TRACE_INT, tp.message, arrayOf(result), tp.throwable - ) - } - return result - } + override fun error(marker: Marker?, msg: String?, t: Throwable?) { + if (!underlyingLogger.isErrorEnabled) return + underlyingLogger.log(marker, fqcn, LocationAwareLogger.ERROR_INT, msg, null, t) + } - override fun throwing(throwable: T): T { - underlyingLogger.log(THROWING, fqcn, LocationAwareLogger.ERROR_INT, "throwing", null, throwable) - throw throwable - } + /** Lazy add a log message if isTraceEnabled is true */ + override fun trace(msg: () -> Any?) { + if (isTraceEnabled) trace(msg.toStringSafe()) + } - private fun buildMessagePattern(len: Int): String { - return (1..len).joinToString( - separator = ", ", - prefix = "entry with (", - postfix = ")" - ) { - "{}" - } - } + /** 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 fun catching(throwable: T) { + if (underlyingLogger.isErrorEnabled) { + underlyingLogger.log( + CATCHING, fqcn, LocationAwareLogger.ERROR_INT, "catching", null, throwable) + } + } + + override fun entry(vararg argArray: Any?) { + if (underlyingLogger.isTraceEnabled(ENTRY)) { + val tp = MessageFormatter.arrayFormat(buildMessagePattern(argArray.size), argArray) + underlyingLogger.log(ENTRY, fqcn, LocationAwareLogger.TRACE_INT, tp.message, null, null) + } + } + + override fun exit() { + if (underlyingLogger.isTraceEnabled(EXIT)) { + underlyingLogger.log(EXIT, fqcn, LocationAwareLogger.TRACE_INT, EXITONLY, null, null) + } + } + + override fun exit(result: T): T { + if (underlyingLogger.isTraceEnabled(EXIT)) { + val tp = MessageFormatter.format(EXITMESSAGE, result) + underlyingLogger.log( + EXIT, + fqcn, + LocationAwareLogger.TRACE_INT, + tp.message, + arrayOf(result), + tp.throwable) + } + return result + } + + override fun throwing(throwable: T): T { + underlyingLogger.log(THROWING, fqcn, LocationAwareLogger.ERROR_INT, "throwing", null, throwable) + throw throwable + } + + private fun buildMessagePattern(len: Int): String { + return (1..len).joinToString(separator = ", ", prefix = "entry with (", postfix = ")") { "{}" } + } } diff --git a/src/jvmMain/kotlin/mu/internal/LocationIgnorantKLogger.kt b/src/jvmMain/kotlin/mu/internal/LocationIgnorantKLogger.kt index 194b01a9..18455e2b 100644 --- a/src/jvmMain/kotlin/mu/internal/LocationIgnorantKLogger.kt +++ b/src/jvmMain/kotlin/mu/internal/LocationIgnorantKLogger.kt @@ -7,183 +7,143 @@ 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 + * 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) - } - } +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/mu/ClassWithLoggingForLocationTesting.kt index aa6edd8b..c99a1354 100644 --- a/src/jvmTest/kotlin/mu/ClassWithLoggingForLocationTesting.kt +++ b/src/jvmTest/kotlin/mu/ClassWithLoggingForLocationTesting.kt @@ -1,29 +1,29 @@ package mu class ClassWithLoggingForLocationTesting { - companion object : KLogging() + companion object : KLogging() - fun log() { - logger.info("test") - } + fun log() { + logger.info("test") + } - fun logLazy() { - logger.info { "test" } - } + fun logLazy() { + logger.info { "test" } + } - fun logNull() { - logger.info(null) - } + fun logNull() { + logger.info(null) + } - fun logEntry(): Pair { - logger.entry(1, 2) - logger.info("log entry body") - return logger.exit(2 to 1) - } + fun logEntry(): Pair { + logger.entry(1, 2) + logger.info("log entry body") + return logger.exit(2 to 1) + } - fun logExitOpt(): Pair? { - logger.entry(1, 2) - logger.info("log entry body") - return logger.exit(null) - } + fun logExitOpt(): Pair? { + logger.entry(1, 2) + logger.info("log entry body") + return logger.exit(null) + } } diff --git a/src/jvmTest/kotlin/mu/KotlinLoggingMDCTest.kt b/src/jvmTest/kotlin/mu/KotlinLoggingMDCTest.kt index 630c42a9..7135ffd8 100644 --- a/src/jvmTest/kotlin/mu/KotlinLoggingMDCTest.kt +++ b/src/jvmTest/kotlin/mu/KotlinLoggingMDCTest.kt @@ -14,210 +14,193 @@ import org.slf4j.MDC @TestInstance(TestInstance.Lifecycle.PER_CLASS) class KotlinLoggingMDCTest { - init { - Configurator.setRootLevel(Level.TRACE) - } - - @BeforeEach - fun setUp() { - MDC.clear() - } + init { + Configurator.setRootLevel(Level.TRACE) + } - @Test - fun `simple pair withLoggingContext`() { - assertNull(MDC.get("a")) + @BeforeEach + fun setUp() { + MDC.clear() + } - withLoggingContext("a" to "c") { + @Test + fun `simple pair withLoggingContext`() { + assertNull(MDC.get("a")) - withLoggingContext("a" to "b") { - assertEquals("b", MDC.get("a")) - } + withLoggingContext("a" to "c") { + withLoggingContext("a" to "b") { assertEquals("b", MDC.get("a")) } - assertEquals("c", MDC.get("a")) - } - assertNull(MDC.get("a")) + assertEquals("c", MDC.get("a")) } - - @Test - fun `simple pair withLoggingContext (restorePrevious=false)`() { - withLoggingContext("a" to "c") { - withLoggingContext("a" to "b", restorePrevious = false) { - assertEquals("b", MDC.get("a")) - } - assertNull(MDC.get("a")) - } - assertNull(MDC.get("a")) - - withLoggingContext("a" to "c", restorePrevious = false) { - withLoggingContext("a" to "b") { - assertEquals("b", MDC.get("a")) - } - assertEquals("c", MDC.get("a")) - } - assertNull(MDC.get("a")) + assertNull(MDC.get("a")) + } + + @Test + fun `simple pair withLoggingContext (restorePrevious=false)`() { + withLoggingContext("a" to "c") { + withLoggingContext("a" to "b", restorePrevious = false) { assertEquals("b", MDC.get("a")) } + assertNull(MDC.get("a")) } + assertNull(MDC.get("a")) - @Test - fun `simple nullable pair withLoggingContext`() { - assertNull(MDC.get("a")) - withLoggingContext("a" to null) { - assertNull(MDC.get("a")) - } - assertNull(MDC.get("a")) - - MDC.put("a", "b") - assertEquals("b", MDC.get("a")) - withLoggingContext("a" to null) { - assertEquals("b", MDC.get("a")) - } - assertEquals("b", MDC.get("a")) + withLoggingContext("a" to "c", restorePrevious = false) { + withLoggingContext("a" to "b") { assertEquals("b", MDC.get("a")) } + assertEquals("c", MDC.get("a")) } - - @Test - fun `multiple pair withLoggingContext`() { - MDC.put("f", "g") - + assertNull(MDC.get("a")) + } + + @Test + fun `simple nullable pair withLoggingContext`() { + assertNull(MDC.get("a")) + withLoggingContext("a" to null) { assertNull(MDC.get("a")) } + assertNull(MDC.get("a")) + + MDC.put("a", "b") + assertEquals("b", MDC.get("a")) + withLoggingContext("a" to null) { assertEquals("b", MDC.get("a")) } + assertEquals("b", MDC.get("a")) + } + + @Test + fun `multiple pair withLoggingContext`() { + MDC.put("f", "g") + + assertAll( + { assertNull(MDC.get("a")) }, + { assertNull(MDC.get("c")) }, + { assertNull(MDC.get("e")) }, + { assertEquals("g", MDC.get("f")) }, + ) + + withLoggingContext("a" to "h", "c" to "i") { + assertAll( + { assertEquals("h", MDC.get("a")) }, + { assertEquals("i", MDC.get("c")) }, + { assertNull(MDC.get("e")) }, + { assertEquals("g", MDC.get("f")) }, + ) + + withLoggingContext("a" to "b", "c" to "d", "e" to null, "f" to null) { assertAll( - { assertNull(MDC.get("a")) }, - { assertNull(MDC.get("c")) }, - { assertNull(MDC.get("e")) }, - { assertEquals("g", MDC.get("f")) }, - ) - - withLoggingContext("a" to "h", "c" to "i") { - assertAll( - { assertEquals("h", MDC.get("a")) }, - { assertEquals("i", MDC.get("c")) }, - { assertNull(MDC.get("e")) }, - { assertEquals("g", MDC.get("f")) }, - ) - - withLoggingContext("a" to "b", "c" to "d", "e" to null, "f" to null) { - assertAll( - { assertEquals("b", MDC.get("a")) }, - { assertEquals("d", MDC.get("c")) }, - { assertNull(MDC.get("e")) }, - { assertEquals("g", MDC.get("f")) }, - ) - } - assertAll( - { assertEquals("h", MDC.get("a")) }, - { assertEquals("i", MDC.get("c")) }, - { assertNull(MDC.get("e")) }, - { assertEquals("g", MDC.get("f")) }, - ) - } - assertAll( - { assertNull(MDC.get("a")) }, - { assertNull(MDC.get("c")) }, + { assertEquals("b", MDC.get("a")) }, + { assertEquals("d", MDC.get("c")) }, { assertNull(MDC.get("e")) }, { assertEquals("g", MDC.get("f")) }, ) + } + assertAll( + { assertEquals("h", MDC.get("a")) }, + { assertEquals("i", MDC.get("c")) }, + { assertNull(MDC.get("e")) }, + { assertEquals("g", MDC.get("f")) }, + ) } - - @Test - fun `multiple pair withLoggingContext (restorePrevious=false)`() { - MDC.put("f", "g") - - assertAll( - { assertNull(MDC.get("a")) }, - { assertNull(MDC.get("c")) }, - { assertNull(MDC.get("e")) }, - { assertEquals("g", MDC.get("f")) }, - ) - - withLoggingContext( - "a" to "b", - "c" to "d", - "e" to null, - "f" to null, - restorePrevious = false - ) { - assertAll( - { assertEquals("b", MDC.get("a")) }, - { assertEquals("d", MDC.get("c")) }, - { assertNull(MDC.get("e")) }, - { assertEquals("g", MDC.get("f")) }, - ) - } - assertAll( - { assertNull(MDC.get("a")) }, - { assertNull(MDC.get("c")) }, - { assertNull(MDC.get("e")) }, - { assertEquals("g", MDC.get("f")) }, - ) + assertAll( + { assertNull(MDC.get("a")) }, + { assertNull(MDC.get("c")) }, + { assertNull(MDC.get("e")) }, + { assertEquals("g", MDC.get("f")) }, + ) + } + + @Test + fun `multiple pair withLoggingContext (restorePrevious=false)`() { + MDC.put("f", "g") + + assertAll( + { assertNull(MDC.get("a")) }, + { assertNull(MDC.get("c")) }, + { assertNull(MDC.get("e")) }, + { assertEquals("g", MDC.get("f")) }, + ) + + withLoggingContext("a" to "b", "c" to "d", "e" to null, "f" to null, restorePrevious = false) { + assertAll( + { assertEquals("b", MDC.get("a")) }, + { assertEquals("d", MDC.get("c")) }, + { assertNull(MDC.get("e")) }, + { assertEquals("g", MDC.get("f")) }, + ) } - - @Test - @Deprecated(message = "Transferred checks in `multiple pair withLoggingContext`") - fun `multiple nullable pair withLoggingContext`() { - assertNull(MDC.get("a")) - assertNull(MDC.get("c")) - MDC.put("e", "f") - withLoggingContext("a" to "b", "c" to null, "e" to null) { - assertEquals("b", MDC.get("a")) - assertNull(MDC.get("c")) - assertEquals("f", MDC.get("e")) - } - assertNull(MDC.get("a")) - assertNull(MDC.get("c")) - assertEquals("f", MDC.get("e")) + assertAll( + { assertNull(MDC.get("a")) }, + { assertNull(MDC.get("c")) }, + { assertNull(MDC.get("e")) }, + { assertEquals("g", MDC.get("f")) }, + ) + } + + @Test + @Deprecated(message = "Transferred checks in `multiple pair withLoggingContext`") + fun `multiple nullable pair withLoggingContext`() { + assertNull(MDC.get("a")) + assertNull(MDC.get("c")) + MDC.put("e", "f") + withLoggingContext("a" to "b", "c" to null, "e" to null) { + assertEquals("b", MDC.get("a")) + assertNull(MDC.get("c")) + assertEquals("f", MDC.get("e")) } - - @ParameterizedTest - @ValueSource(booleans = [true, false]) - fun `map withLoggingContext`(restorePrevious: Boolean) { + assertNull(MDC.get("a")) + assertNull(MDC.get("c")) + assertEquals("f", MDC.get("e")) + } + + @ParameterizedTest + @ValueSource(booleans = [true, false]) + fun `map withLoggingContext`(restorePrevious: Boolean) { + assertAll( + { assertNull(MDC.get("a")) }, + { assertNull(MDC.get("c")) }, + { assertNull(MDC.get("e")) }, + { assertNull(MDC.get("f")) }, + { assertNull(MDC.get("k")) }, + ) + + MDC.put("e", "g") + MDC.put("k", "l") + + withLoggingContext(mapOf("a" to "b", "c" to "d", "e" to null, "f" to "h"), restorePrevious) { + assertAll( + { assertEquals("b", MDC.get("a")) }, + { assertEquals("d", MDC.get("c")) }, + { assertEquals("g", MDC.get("e")) }, + { assertEquals("h", MDC.get("f")) }, + { assertEquals("l", MDC.get("k")) }, + ) + + withLoggingContext(mapOf("a" to "b", "e" to "i", "f" to "j")) { assertAll( - { assertNull(MDC.get("a")) }, - { assertNull(MDC.get("c")) }, - { assertNull(MDC.get("e")) }, - { assertNull(MDC.get("f")) }, - { assertNull(MDC.get("k")) }, - ) - - MDC.put("e", "g") - MDC.put("k", "l") - - withLoggingContext(mapOf("a" to "b", "c" to "d", "e" to null, "f" to "h"), restorePrevious) { - assertAll( - { assertEquals("b", MDC.get("a")) }, - { assertEquals("d", MDC.get("c")) }, - { assertEquals("g", MDC.get("e")) }, - { assertEquals("h", MDC.get("f")) }, - { assertEquals("l", MDC.get("k")) }, - ) - - withLoggingContext(mapOf("a" to "b", "e" to "i", "f" to "j")) { - assertAll( - { assertEquals("b", MDC.get("a")) }, - { assertEquals("d", MDC.get("c")) }, - { assertEquals("i", MDC.get("e")) }, - { assertEquals("j", MDC.get("f")) }, - { assertEquals("l", MDC.get("k")) }, - ) - } - - assertAll( - { assertEquals("b", MDC.get("a")) }, - { assertEquals("d", MDC.get("c")) }, - { assertEquals("g", MDC.get("e")) }, - { assertEquals("h", MDC.get("f")) }, - { assertEquals("l", MDC.get("k")) }, - ) - } - - assertAll( - { assertNull(MDC.get("a")) }, - { assertNull(MDC.get("c")) }, - { - if (restorePrevious) { - assertEquals("g", MDC.get("e")) - } else { - assertNull(MDC.get("e")) - } - }, - { assertNull(MDC.get("f")) }, + { assertEquals("b", MDC.get("a")) }, + { assertEquals("d", MDC.get("c")) }, + { assertEquals("i", MDC.get("e")) }, + { assertEquals("j", MDC.get("f")) }, { assertEquals("l", MDC.get("k")) }, ) + } + + assertAll( + { assertEquals("b", MDC.get("a")) }, + { assertEquals("d", MDC.get("c")) }, + { assertEquals("g", MDC.get("e")) }, + { assertEquals("h", MDC.get("f")) }, + { assertEquals("l", MDC.get("k")) }, + ) } + + assertAll( + { assertNull(MDC.get("a")) }, + { assertNull(MDC.get("c")) }, + { + if (restorePrevious) { + assertEquals("g", MDC.get("e")) + } else { + assertNull(MDC.get("e")) + } + }, + { assertNull(MDC.get("f")) }, + { assertEquals("l", MDC.get("k")) }, + ) + } } diff --git a/src/jvmTest/kotlin/mu/KotlinLoggingTest.kt b/src/jvmTest/kotlin/mu/KotlinLoggingTest.kt index c53e194b..595b9da1 100644 --- a/src/jvmTest/kotlin/mu/KotlinLoggingTest.kt +++ b/src/jvmTest/kotlin/mu/KotlinLoggingTest.kt @@ -5,28 +5,29 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.assertAll import org.slf4j.LoggerFactory -private val logger = KotlinLogging.logger { } +private val logger = KotlinLogging.logger {} private val loggerFromSlf4j = KotlinLogging.logger(LoggerFactory.getLogger("mu.slf4jLogger")) -private val loggerFromSlf4jExtension = LoggerFactory.getLogger("mu.slf4jLoggerExtension").toKLogger() +private val loggerFromSlf4jExtension = + LoggerFactory.getLogger("mu.slf4jLoggerExtension").toKLogger() class ForKotlinLoggingTest { - val loggerInClass = KotlinLogging.logger { } + val loggerInClass = KotlinLogging.logger {} - companion object { - val loggerInCompanion = 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) }, - ) - } + @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/jvmTest/kotlin/mu/LoggingTest.kt b/src/jvmTest/kotlin/mu/LoggingTest.kt index 70ce8a1e..0f895cba 100644 --- a/src/jvmTest/kotlin/mu/LoggingTest.kt +++ b/src/jvmTest/kotlin/mu/LoggingTest.kt @@ -1,5 +1,6 @@ package mu +import java.io.StringWriter import org.apache.logging.log4j.Level import org.apache.logging.log4j.LogManager import org.apache.logging.log4j.core.Appender @@ -12,256 +13,268 @@ import org.junit.jupiter.api.Assertions.assertTrue import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test import org.junit.jupiter.api.assertAll -import java.io.StringWriter class ClassWithLogging { - companion object : KLogging() - - fun test() { - logger.info { "test ClassWithLogging" } - } - - fun testThrowable() { - val ex = Throwable() - logger.trace(ex) { "test ClassWithLogging" } - } - - fun testNullableThrowable() { - val ex: Throwable? = null - logger.trace(ex) { "test ClassWithLogging" } - } - - fun testMarker() { - val marker = KMarkerFactory.getMarker("MARKER") - logger.trace(marker) { "test ClassWithLogging" } - } - - fun testMarkerThrowable() { - val marker = KMarkerFactory.getMarker("MARKER") - val ex = Throwable() - logger.trace(marker, ex) { "test ClassWithLogging" } - } - - fun testFormatting() { - logger.info("Message: {}", "String with {} curly braces") - } + companion object : KLogging() + + fun test() { + logger.info { "test ClassWithLogging" } + } + + fun testThrowable() { + val ex = Throwable() + logger.trace(ex) { "test ClassWithLogging" } + } + + fun testNullableThrowable() { + val ex: Throwable? = null + logger.trace(ex) { "test ClassWithLogging" } + } + + fun testMarker() { + val marker = KMarkerFactory.getMarker("MARKER") + logger.trace(marker) { "test ClassWithLogging" } + } + + fun testMarkerThrowable() { + val marker = KMarkerFactory.getMarker("MARKER") + val ex = Throwable() + logger.trace(marker, ex) { "test ClassWithLogging" } + } + + fun testFormatting() { + logger.info("Message: {}", "String with {} curly braces") + } } open class ClassHasLogging : KLoggable { - override val logger = logger() - fun test() { - logger.info { "test ClassHasLogging" } - } + override val logger = logger() + fun test() { + logger.info { "test ClassHasLogging" } + } } /** - * This class demonstrates the disadvantage of inheriting KLoggable in a class instead of companion object - * the logger name will be of the sub-class - * ie: it is not possible to log with parent class name this way + * This class demonstrates the disadvantage of inheriting KLoggable in a class instead of companion + * object the logger name will be of the sub-class ie: it is not possible to log with parent class + * name this way */ class ClassInheritLogging : ClassHasLogging() class ClassWithNamedLogging { - companion object : Any(), KLoggable by NamedKLogging("mu.ClassWithNamedLogging") + companion object : Any(), KLoggable by NamedKLogging("mu.ClassWithNamedLogging") - fun test() { - logger.info { "test ClassWithNamedLogging" } - } + fun test() { + logger.info { "test ClassWithNamedLogging" } + } } class CompanionHasLogging { - companion object : Any(), KLoggable { - override val logger = logger() - } + companion object : Any(), KLoggable { + override val logger = logger() + } - fun test() { - logger.info { "test CompanionHasLogging" } - } + fun test() { + logger.info { "test CompanionHasLogging" } + } } class ChildClassWithLogging { - companion object : KLogging() + companion object : KLogging() - fun test() { - logger.info { "test ChildClassWithLogging" } - } + fun test() { + logger.info { "test ChildClassWithLogging" } + } } data class ClassWithIncorrectToString(val someVariable: String? = null) { - override fun toString(): String { - return someVariable!!.toString() - } + override fun toString(): String { + return someVariable!!.toString() + } } class LambdaRaisesError { - companion object : KLogging() + companion object : KLogging() - fun test() { - val problematicClass = ClassWithIncorrectToString() + fun test() { + val problematicClass = ClassWithIncorrectToString() - logger.info { " $problematicClass" } - } + logger.info { " $problematicClass" } + } } -fun newPatternLayout(pattern: String): PatternLayout = PatternLayout.newBuilder().withPattern(pattern).build() +fun newPatternLayout(pattern: String): PatternLayout = + PatternLayout.newBuilder().withPattern(pattern).build() fun addAppender(appender: Appender) { - val context = LogManager.getContext(false) as org.apache.logging.log4j.core.LoggerContext - context.configuration.rootLogger.addAppender(appender, null, null) - appender.start() + val context = LogManager.getContext(false) as org.apache.logging.log4j.core.LoggerContext + context.configuration.rootLogger.addAppender(appender, null, null) + appender.start() } fun removeAppender(appender: Appender) { - val context = LogManager.getContext(false) as org.apache.logging.log4j.core.LoggerContext - context.configuration.rootLogger.removeAppender(appender.name) - appender.stop() + val context = LogManager.getContext(false) as org.apache.logging.log4j.core.LoggerContext + context.configuration.rootLogger.removeAppender(appender.name) + appender.stop() } class LoggingTest { - private val appenderWithWriter: AppenderWithWriter = AppenderWithWriter() - - init { - Configurator.setRootLevel(Level.TRACE) + private val appenderWithWriter: AppenderWithWriter = AppenderWithWriter() + + init { + Configurator.setRootLevel(Level.TRACE) + } + + @BeforeEach + fun setupAppender() { + addAppender(appenderWithWriter.appender) + } + + @AfterEach + fun removeAppender() { + removeAppender(appenderWithWriter.appender) + } + + @Test + fun testMessages0() { + ClassWithLogging().apply { + test() + testThrowable() + testNullableThrowable() } - - @BeforeEach - fun setupAppender() { - addAppender(appenderWithWriter.appender) - } - - @AfterEach - fun removeAppender() { - removeAppender(appenderWithWriter.appender) - } - - @Test - fun testMessages0() { - ClassWithLogging().apply { - test() - testThrowable() - testNullableThrowable() - } - appenderWithWriter.writer.flush() - val lines = appenderWithWriter.writer.toString().trim() + appenderWithWriter.writer.flush() + val lines = + appenderWithWriter.writer + .toString() + .trim() .replace("\r", "\n") .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("java.lang.Throwable: null", lines[2].trim()) }, - { assertTrue(lines[3].trim().startsWith("at mu.ClassWithLogging.testThrowable(")) }, - { assertEquals("TRACE mu.ClassWithLogging - test ClassWithLogging", lines[lines.size - 1].trim()) }, - ) - } + assertAll( + { assertEquals("INFO mu.ClassWithLogging - test ClassWithLogging", lines[0].trim()) }, + { assertEquals("TRACE mu.ClassWithLogging - test ClassWithLogging", lines[1].trim()) }, + { assertEquals("java.lang.Throwable: null", lines[2].trim()) }, + { assertTrue(lines[3].trim().startsWith("at mu.ClassWithLogging.testThrowable(")) }, + { + assertEquals( + "TRACE mu.ClassWithLogging - test ClassWithLogging", lines[lines.size - 1].trim()) + }, + ) + } - @Test - fun testMessages1() { - ClassWithLogging().apply { - testMarker() - testMarkerThrowable() - } - appenderWithWriter.writer.flush() - val lines = appenderWithWriter.writer.toString().trim() + @Test + fun testMessages1() { + ClassWithLogging().apply { + testMarker() + testMarkerThrowable() + } + appenderWithWriter.writer.flush() + val lines = + appenderWithWriter.writer + .toString() + .trim() .replace("\r", "\n") .replace("\n\n", "\n") .split("\n") - assertAll( - { assertEquals("TRACE mu.ClassWithLogging MARKER - test ClassWithLogging", lines[0].trim()) }, - { assertEquals("TRACE mu.ClassWithLogging MARKER - test ClassWithLogging", lines[1].trim()) }, - { assertEquals("java.lang.Throwable: null", lines[2].trim()) }, - { assertTrue(lines[3].trim().startsWith("at mu.ClassWithLogging.testMarkerThrowable(")) }, - ) - } - - @Test - fun testMessages2() { - ClassInheritLogging().test() - appenderWithWriter.writer.flush() - assertEquals( - "INFO mu.ClassInheritLogging - test ClassHasLogging", appenderWithWriter.writer.toString().trim() - ) - } - - @Test - fun testMessages3() { - ChildClassWithLogging().test() - appenderWithWriter.writer.flush() - assertEquals( - "INFO mu.ChildClassWithLogging - test ChildClassWithLogging", appenderWithWriter.writer.toString().trim() - ) - } - - @Test - fun testMessages4() { - ClassWithNamedLogging().test() - appenderWithWriter.writer.flush() - assertEquals( - "INFO mu.ClassWithNamedLogging - test ClassWithNamedLogging", appenderWithWriter.writer.toString().trim() - ) - } - - @Test - fun testMessages5() { - ClassHasLogging().test() - appenderWithWriter.writer.flush() - assertEquals( - "INFO mu.ClassHasLogging - test ClassHasLogging", appenderWithWriter.writer.toString().trim() - ) - } - - @Test - fun testMessages6() { - CompanionHasLogging().test() - appenderWithWriter.writer.flush() - assertEquals( - "INFO mu.CompanionHasLogging - test CompanionHasLogging", appenderWithWriter.writer.toString().trim() - ) - } - - @Test - fun shouldNotFailForFailingLambdas() { - LambdaRaisesError().test() - appenderWithWriter.writer.flush() - assertEquals( - "INFO mu.LambdaRaisesError - Log message invocation failed: java.lang.NullPointerException", - appenderWithWriter.writer.toString().trim() - ) - } - - @Test - fun placeholderFormatting() { - ClassWithLogging().testFormatting() - appenderWithWriter.writer.flush() - assertEquals( - "INFO mu.ClassWithLogging - Message: String with {} curly braces", appenderWithWriter.writer.toString().trim() - ) - } - - @Test - fun `check underlyingLogger property`() { - assertEquals("mu.ClassHasLogging", ClassHasLogging().logger.underlyingLogger.name) - } + assertAll( + { + assertEquals("TRACE mu.ClassWithLogging MARKER - test ClassWithLogging", lines[0].trim()) + }, + { + assertEquals("TRACE mu.ClassWithLogging MARKER - test ClassWithLogging", lines[1].trim()) + }, + { assertEquals("java.lang.Throwable: null", lines[2].trim()) }, + { assertTrue(lines[3].trim().startsWith("at mu.ClassWithLogging.testMarkerThrowable(")) }, + ) + } + + @Test + fun testMessages2() { + ClassInheritLogging().test() + appenderWithWriter.writer.flush() + assertEquals( + "INFO mu.ClassInheritLogging - test ClassHasLogging", + appenderWithWriter.writer.toString().trim()) + } + + @Test + fun testMessages3() { + ChildClassWithLogging().test() + appenderWithWriter.writer.flush() + assertEquals( + "INFO mu.ChildClassWithLogging - test ChildClassWithLogging", + appenderWithWriter.writer.toString().trim()) + } + + @Test + fun testMessages4() { + ClassWithNamedLogging().test() + appenderWithWriter.writer.flush() + assertEquals( + "INFO mu.ClassWithNamedLogging - test ClassWithNamedLogging", + appenderWithWriter.writer.toString().trim()) + } + + @Test + fun testMessages5() { + ClassHasLogging().test() + appenderWithWriter.writer.flush() + assertEquals( + "INFO mu.ClassHasLogging - test ClassHasLogging", + appenderWithWriter.writer.toString().trim()) + } + + @Test + fun testMessages6() { + CompanionHasLogging().test() + appenderWithWriter.writer.flush() + assertEquals( + "INFO mu.CompanionHasLogging - test CompanionHasLogging", + appenderWithWriter.writer.toString().trim()) + } + + @Test + fun shouldNotFailForFailingLambdas() { + LambdaRaisesError().test() + appenderWithWriter.writer.flush() + assertEquals( + "INFO mu.LambdaRaisesError - Log message invocation failed: java.lang.NullPointerException", + appenderWithWriter.writer.toString().trim()) + } + + @Test + fun placeholderFormatting() { + ClassWithLogging().testFormatting() + appenderWithWriter.writer.flush() + assertEquals( + "INFO mu.ClassWithLogging - Message: String with {} curly braces", + appenderWithWriter.writer.toString().trim()) + } + + @Test + fun `check underlyingLogger property`() { + assertEquals("mu.ClassHasLogging", ClassHasLogging().logger.underlyingLogger.name) + } } 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) }, - ) - } + @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) }, + ) + } } 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 - ) + val appender: Appender = + WriterAppender.createAppender( + newPatternLayout(pattern), null, writer, "writer", false, true) ) diff --git a/src/jvmTest/kotlin/mu/LoggingWithLocationTest.kt b/src/jvmTest/kotlin/mu/LoggingWithLocationTest.kt index fa96b53a..48f73e8e 100644 --- a/src/jvmTest/kotlin/mu/LoggingWithLocationTest.kt +++ b/src/jvmTest/kotlin/mu/LoggingWithLocationTest.kt @@ -8,66 +8,70 @@ import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test class LoggingWithLocationTest { - private val appenderWithWriter: AppenderWithWriter = AppenderWithWriter("%p %C{1}.%M(%L) - %m%n") + private val appenderWithWriter: AppenderWithWriter = AppenderWithWriter("%p %C{1}.%M(%L) - %m%n") - init { - Configurator.setRootLevel(Level.TRACE) - } + init { + Configurator.setRootLevel(Level.TRACE) + } - @BeforeEach - fun setupAppender() { - addAppender(appenderWithWriter.appender) - } + @BeforeEach + fun setupAppender() { + addAppender(appenderWithWriter.appender) + } - @AfterEach - fun removeAppender() { - removeAppender(appenderWithWriter.appender) - } + @AfterEach + fun removeAppender() { + removeAppender(appenderWithWriter.appender) + } - @Test - fun testLoggingWithLocation() { - ClassWithLoggingForLocationTesting().log() - assertEquals( - "INFO ClassWithLoggingForLocationTesting.log(7) - test", appenderWithWriter.writer.toString().trim() - ) - } + @Test + fun testLoggingWithLocation() { + ClassWithLoggingForLocationTesting().log() + assertEquals( + "INFO ClassWithLoggingForLocationTesting.log(7) - test", + appenderWithWriter.writer.toString().trim()) + } - @Test - fun testLazyLoggingWithLocation() { - ClassWithLoggingForLocationTesting().logLazy() - assertEquals( - "INFO ClassWithLoggingForLocationTesting.logLazy(11) - test", appenderWithWriter.writer.toString().trim() - ) - } + @Test + fun testLazyLoggingWithLocation() { + ClassWithLoggingForLocationTesting().logLazy() + assertEquals( + "INFO ClassWithLoggingForLocationTesting.logLazy(11) - test", + appenderWithWriter.writer.toString().trim()) + } - @Test - fun testNullLoggingWithLocation() { - ClassWithLoggingForLocationTesting().logNull() - assertEquals( - "INFO ClassWithLoggingForLocationTesting.logNull(15) - null", appenderWithWriter.writer.toString().trim() - ) - } + @Test + fun testNullLoggingWithLocation() { + ClassWithLoggingForLocationTesting().logNull() + assertEquals( + "INFO ClassWithLoggingForLocationTesting.logNull(15) - null", + appenderWithWriter.writer.toString().trim()) + } - @Test - fun testNullLoggingWithLocationEntryExit() { - ClassWithLoggingForLocationTesting().logEntry() - @Suppress("MaxLineLength") - assertEquals( - "TRACE ClassWithLoggingForLocationTesting.logEntry(19) - entry with (1, 2)" + System.lineSeparator() + "INFO " + "ClassWithLoggingForLocationTesting.logEntry(20) - log entry body" + System.lineSeparator() + "TRACE " + "ClassWithLoggingForLocationTesting.logEntry(21) - exit with ((2, 1))", - appenderWithWriter.writer.toString().trim() - ) - } + @Test + fun testNullLoggingWithLocationEntryExit() { + ClassWithLoggingForLocationTesting().logEntry() + @Suppress("MaxLineLength") + assertEquals( + "TRACE ClassWithLoggingForLocationTesting.logEntry(19) - entry with (1, 2)" + + System.lineSeparator() + + "INFO " + + "ClassWithLoggingForLocationTesting.logEntry(20) - log entry body" + + System.lineSeparator() + + "TRACE " + + "ClassWithLoggingForLocationTesting.logEntry(21) - exit with ((2, 1))", + appenderWithWriter.writer.toString().trim()) + } - @Test - fun testNullLoggingWithLocationEntryExitOpt() { - ClassWithLoggingForLocationTesting().logExitOpt() - assertEquals( - "TRACE ClassWithLoggingForLocationTesting.logExitOpt(25) - entry with (1, 2)" + System.lineSeparator() + - "INFO ClassWithLoggingForLocationTesting.logExitOpt(26) - log entry body" + System.lineSeparator() + - "TRACE ClassWithLoggingForLocationTesting.logExitOpt(27) - exit with (null)", - appenderWithWriter.writer.toString().trim() - ) - } + @Test + fun testNullLoggingWithLocationEntryExitOpt() { + ClassWithLoggingForLocationTesting().logExitOpt() + assertEquals( + "TRACE ClassWithLoggingForLocationTesting.logExitOpt(25) - entry with (1, 2)" + + System.lineSeparator() + + "INFO ClassWithLoggingForLocationTesting.logExitOpt(26) - log entry body" + + System.lineSeparator() + + "TRACE ClassWithLoggingForLocationTesting.logExitOpt(27) - exit with (null)", + appenderWithWriter.writer.toString().trim()) + } } - - diff --git a/src/jvmTest/kotlin/mu/internal/KLoggerNameResolverTest.kt b/src/jvmTest/kotlin/mu/internal/KLoggerNameResolverTest.kt index 746b5182..296d9dea 100644 --- a/src/jvmTest/kotlin/mu/internal/KLoggerNameResolverTest.kt +++ b/src/jvmTest/kotlin/mu/internal/KLoggerNameResolverTest.kt @@ -1,78 +1,77 @@ package mu.internal +import java.util.stream.Stream import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.TestInstance import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.Arguments import org.junit.jupiter.params.provider.MethodSource -import java.util.stream.Stream @TestInstance(TestInstance.Lifecycle.PER_CLASS) class KLoggerNameResolverTest { - @ParameterizedTest - @MethodSource("testNames") - fun testNames(expectedName: String, clazz: Class<*>) { - assertEquals(expectedName, KLoggerNameResolver.name(clazz)) - } + @ParameterizedTest + @MethodSource("testNames") + fun testNames(expectedName: String, clazz: Class<*>) { + assertEquals(expectedName, KLoggerNameResolver.name(clazz)) + } - 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("java.lang.Object", Any().javaClass), - Arguments.of("mu.internal.KLoggerNameResolverTest\$testNames$1", object {}.javaClass), - Arguments.of( - "mu.internal.BaseClass\$InnerClass\$Obj", - BaseClass.InnerClass.Obj::class.java, - ), - Arguments.of( - "mu.internal.BaseClass\$InnerClass\$Obj", - BaseClass.InnerClass.Obj.javaClass, - ), - Arguments.of( - "mu.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) - ) + 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("java.lang.Object", Any().javaClass), + Arguments.of("mu.internal.KLoggerNameResolverTest\$testNames$1", object {}.javaClass), + Arguments.of( + "mu.internal.BaseClass\$InnerClass\$Obj", + BaseClass.InnerClass.Obj::class.java, + ), + Arguments.of( + "mu.internal.BaseClass\$InnerClass\$Obj", + BaseClass.InnerClass.Obj.javaClass, + ), + Arguments.of( + "mu.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)) } open class BaseClass { - companion object - class InnerClass { - object Obj - companion object CmpObj - } + companion object + class InnerClass { + object Obj + companion object CmpObj + } } class ChildClass : BaseClass() { - companion object + companion object } object Singleton -interface MyInterface +interface MyInterface @Suppress("unused") class Foo { - object Bar - object Bar2 + object Bar + object Bar2 - val z = Bar2 + val z = Bar2 - companion object { - @JvmField - val Bar3 = Foo().z - } + companion object { + @JvmField val Bar3 = Foo().z + } } class PrivateCompanion { - val companionClass: Class<*> = Companion::class.java - private companion object + val companionClass: Class<*> = Companion::class.java + private companion object } diff --git a/src/jvmTest/kotlin/mu/internal/MessageInvokerJavaTest.kt b/src/jvmTest/kotlin/mu/internal/MessageInvokerJavaTest.kt index 579d57aa..4dc53979 100644 --- a/src/jvmTest/kotlin/mu/internal/MessageInvokerJavaTest.kt +++ b/src/jvmTest/kotlin/mu/internal/MessageInvokerJavaTest.kt @@ -1,30 +1,32 @@ package mu.internal +import kotlin.test.assertEquals import org.junit.jupiter.api.Test import org.junit.jupiter.api.assertThrows -import kotlin.test.assertEquals class MessageInvokerJavaTest { - @Test - fun toStringSafeChecks() { - assertEquals("hi", { "hi" }.toStringSafe()) - } + @Test + fun toStringSafeChecks() { + assertEquals("hi", { "hi" }.toStringSafe()) + } - @Test - fun toStringSafeChecksThrowException() { - assertEquals("Log message invocation failed: java.lang.Exception: hi", { throw Exception("hi") }.toStringSafe()) - } + @Test + fun toStringSafeChecksThrowException() { + assertEquals( + "Log message invocation failed: java.lang.Exception: hi", + { throw Exception("hi") }.toStringSafe()) + } - @Test - fun toStringSafeChecksThrowExceptionWithSystemProperty() { - assertThrows { - System.setProperty("kotlin-logging.throwOnMessageError", "") - try { - { throw Exception("hi") }.toStringSafe() - } finally { - System.clearProperty("kotlin-logging.throwOnMessageError") - } - } + @Test + fun toStringSafeChecksThrowExceptionWithSystemProperty() { + assertThrows { + System.setProperty("kotlin-logging.throwOnMessageError", "") + try { + { throw Exception("hi") }.toStringSafe() + } finally { + System.clearProperty("kotlin-logging.throwOnMessageError") + } } + } } diff --git a/src/nativeMain/kotlin/mu/Appender.kt b/src/nativeMain/kotlin/mu/Appender.kt index 04c84395..664d72ac 100644 --- a/src/nativeMain/kotlin/mu/Appender.kt +++ b/src/nativeMain/kotlin/mu/Appender.kt @@ -1,11 +1,11 @@ package mu public interface Appender { - public val includePrefix: Boolean + public val includePrefix: Boolean - public fun trace(loggerName: String, message: String) - public fun debug(loggerName: String, message: String) - public fun info(loggerName: String, message: String) - public fun warn(loggerName: String, message: String) - public fun error(loggerName: String, message: String) + public fun trace(loggerName: String, message: String) + public fun debug(loggerName: String, message: String) + public fun info(loggerName: String, message: String) + public fun warn(loggerName: String, message: String) + public fun error(loggerName: String, message: String) } diff --git a/src/nativeMain/kotlin/mu/ConsoleOutputAppender.kt b/src/nativeMain/kotlin/mu/ConsoleOutputAppender.kt index 065d3c04..e5494a0c 100644 --- a/src/nativeMain/kotlin/mu/ConsoleOutputAppender.kt +++ b/src/nativeMain/kotlin/mu/ConsoleOutputAppender.kt @@ -4,13 +4,13 @@ import platform.posix.fprintf import platform.posix.stderr public object ConsoleOutputAppender : Appender { - override val includePrefix: Boolean = true - public override fun trace(loggerName: String, message: String): Unit = println(message) - public override fun debug(loggerName: String, message: String): Unit = println(message) - public override fun info(loggerName: String, message: String): Unit = println(message) - public override fun warn(loggerName: String, message: String): Unit = println(message) + override val includePrefix: Boolean = true + public override fun trace(loggerName: String, message: String): Unit = println(message) + public override fun debug(loggerName: String, message: String): Unit = println(message) + public override fun info(loggerName: String, message: String): Unit = println(message) + public override fun warn(loggerName: String, message: String): Unit = println(message) - override fun error(loggerName: String, message: String) { - fprintf(stderr, "$message\n") - } + override fun error(loggerName: String, message: String) { + fprintf(stderr, "$message\n") + } } diff --git a/src/nativeMain/kotlin/mu/DefaultMessageFormatter.kt b/src/nativeMain/kotlin/mu/DefaultMessageFormatter.kt index 6d16ef5e..5906ca61 100644 --- a/src/nativeMain/kotlin/mu/DefaultMessageFormatter.kt +++ b/src/nativeMain/kotlin/mu/DefaultMessageFormatter.kt @@ -3,43 +3,63 @@ package mu import mu.internal.toStringSafe public object DefaultMessageFormatter : Formatter { - public override fun formatMessage(includePrefix: Boolean, level: KotlinLoggingLevel, loggerName: String, msg: () -> Any?): String = - "${prefix(includePrefix, level, loggerName)}${msg.toStringSafe()}" + public override fun formatMessage( + includePrefix: Boolean, + level: KotlinLoggingLevel, + loggerName: String, + msg: () -> Any? + ): String = "${prefix(includePrefix, level, loggerName)}${msg.toStringSafe()}" - public override fun formatMessage(includePrefix: Boolean, level: KotlinLoggingLevel, loggerName: String, t: Throwable?, msg: () -> Any?): String = - "${prefix(includePrefix, level, loggerName)}${msg.toStringSafe()}${t.throwableToString()}" + public override fun formatMessage( + includePrefix: Boolean, + level: KotlinLoggingLevel, + loggerName: String, + t: Throwable?, + msg: () -> Any? + ): String = + "${prefix(includePrefix, level, loggerName)}${msg.toStringSafe()}${t.throwableToString()}" - public override fun formatMessage(includePrefix: Boolean, level: KotlinLoggingLevel, loggerName: String, marker: Marker?, msg: () -> Any?): String = - "${prefix(includePrefix, level, loggerName)}${marker?.getName()} ${msg.toStringSafe()}" + public override fun formatMessage( + includePrefix: Boolean, + level: KotlinLoggingLevel, + loggerName: String, + marker: Marker?, + msg: () -> Any? + ): String = + "${prefix(includePrefix, level, loggerName)}${marker?.getName()} ${msg.toStringSafe()}" - public override fun formatMessage( - includePrefix: Boolean, - level: KotlinLoggingLevel, - loggerName: String, - marker: Marker?, - t: Throwable?, - msg: () -> Any? - ): String = - "${prefix(includePrefix, level, loggerName)}${marker?.getName()} ${msg.toStringSafe()}${t.throwableToString()}" + public override fun formatMessage( + includePrefix: Boolean, + level: KotlinLoggingLevel, + loggerName: String, + marker: Marker?, + t: Throwable?, + msg: () -> Any? + ): String = + "${prefix(includePrefix, level, loggerName)}${marker?.getName()} ${msg.toStringSafe()}${t.throwableToString()}" - private fun prefix(includePrefix: Boolean, level: KotlinLoggingLevel, loggerName: String): String { - return if (includePrefix) { - "${level.name}: [$loggerName] " - } else { - "" - } + private fun prefix( + includePrefix: Boolean, + level: KotlinLoggingLevel, + loggerName: String + ): String { + return if (includePrefix) { + "${level.name}: [$loggerName] " + } else { + "" } + } - private fun Throwable?.throwableToString(): String { - if (this == null) { - return "" - } - var msg = "" - var current = this - while (current != null && current.cause != current) { - msg += ", Caused by: '${current.message}'" - current = current.cause - } - return msg + private fun Throwable?.throwableToString(): String { + if (this == null) { + return "" } + var msg = "" + var current = this + while (current != null && current.cause != current) { + msg += ", Caused by: '${current.message}'" + current = current.cause + } + return msg + } } diff --git a/src/nativeMain/kotlin/mu/Formatter.kt b/src/nativeMain/kotlin/mu/Formatter.kt index cf4b4907..0ff3cadd 100644 --- a/src/nativeMain/kotlin/mu/Formatter.kt +++ b/src/nativeMain/kotlin/mu/Formatter.kt @@ -1,15 +1,32 @@ package mu public interface Formatter { - public fun formatMessage(includePrefix: Boolean, level: KotlinLoggingLevel, loggerName: String, msg: () -> Any?): String - public fun formatMessage(includePrefix: Boolean, level: KotlinLoggingLevel, loggerName: String, t: Throwable?, msg: () -> Any?): String - public fun formatMessage(includePrefix: Boolean, level: KotlinLoggingLevel, loggerName: String, marker: Marker?, msg: () -> Any?): String - public fun formatMessage( - includePrefix: Boolean, - level: KotlinLoggingLevel, - loggerName: String, - marker: Marker?, - t: Throwable?, - msg: () -> Any? - ): String + public fun formatMessage( + includePrefix: Boolean, + level: KotlinLoggingLevel, + loggerName: String, + msg: () -> Any? + ): String + public fun formatMessage( + includePrefix: Boolean, + level: KotlinLoggingLevel, + loggerName: String, + t: Throwable?, + msg: () -> Any? + ): String + public fun formatMessage( + includePrefix: Boolean, + level: KotlinLoggingLevel, + loggerName: String, + marker: Marker?, + msg: () -> Any? + ): String + public fun formatMessage( + includePrefix: Boolean, + level: KotlinLoggingLevel, + loggerName: String, + marker: Marker?, + t: Throwable?, + msg: () -> Any? + ): String } diff --git a/src/nativeMain/kotlin/mu/KLogger.kt b/src/nativeMain/kotlin/mu/KLogger.kt index 4faef220..8228bd47 100644 --- a/src/nativeMain/kotlin/mu/KLogger.kt +++ b/src/nativeMain/kotlin/mu/KLogger.kt @@ -2,128 +2,78 @@ package mu public actual interface KLogger { - /** - * 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 + /** 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/nativeMain/kotlin/mu/KMarkerFactory.kt b/src/nativeMain/kotlin/mu/KMarkerFactory.kt index 3e92f599..f806c4d7 100644 --- a/src/nativeMain/kotlin/mu/KMarkerFactory.kt +++ b/src/nativeMain/kotlin/mu/KMarkerFactory.kt @@ -4,5 +4,5 @@ import mu.internal.MarkerNative public actual object KMarkerFactory { - public actual fun getMarker(name: String): Marker = MarkerNative(name) + public actual fun getMarker(name: String): Marker = MarkerNative(name) } diff --git a/src/nativeMain/kotlin/mu/KotlinLogging.kt b/src/nativeMain/kotlin/mu/KotlinLogging.kt index 2e7f68e5..26b17971 100644 --- a/src/nativeMain/kotlin/mu/KotlinLogging.kt +++ b/src/nativeMain/kotlin/mu/KotlinLogging.kt @@ -2,15 +2,15 @@ package mu import mu.internal.KLoggerLinux - public actual object KotlinLogging { - /** - * This method allow defining the logger in a file in the following way: - * ``` - * val logger = KotlinLogging.logger {} - * ``` - */ - public actual fun logger(func: () -> Unit): KLogger = KLoggerLinux(func::class.qualifiedName ?: "") + /** + * This method allow defining the logger in a file in the following way: + * ``` + * val logger = KotlinLogging.logger {} + * ``` + */ + public actual fun logger(func: () -> Unit): KLogger = + KLoggerLinux(func::class.qualifiedName ?: "") - public actual fun logger(name: String): KLogger = KLoggerLinux(name) + public actual fun logger(name: String): KLogger = KLoggerLinux(name) } diff --git a/src/nativeMain/kotlin/mu/KotlinLoggingConfiguration.kt b/src/nativeMain/kotlin/mu/KotlinLoggingConfiguration.kt index ca9091fe..ffe4e538 100644 --- a/src/nativeMain/kotlin/mu/KotlinLoggingConfiguration.kt +++ b/src/nativeMain/kotlin/mu/KotlinLoggingConfiguration.kt @@ -6,22 +6,22 @@ public expect val DefaultAppender: Appender @Suppress("ObjectPropertyName") public object KotlinLoggingConfiguration { - private val _logLevel = AtomicReference(KotlinLoggingLevel.INFO) - public var logLevel: KotlinLoggingLevel - get() = _logLevel.value - set(value) { - _logLevel.value = value - } - private val _appender = AtomicReference(DefaultAppender) - public var appender: Appender - get() = _appender.value - set(value) { - _appender.value = value - } - private val _formatter = AtomicReference(DefaultMessageFormatter) - public var formatter: Formatter - get() = _formatter.value - set(value) { - _formatter.value = value - } + private val _logLevel = AtomicReference(KotlinLoggingLevel.INFO) + public var logLevel: KotlinLoggingLevel + get() = _logLevel.value + set(value) { + _logLevel.value = value + } + private val _appender = AtomicReference(DefaultAppender) + public var appender: Appender + get() = _appender.value + set(value) { + _appender.value = value + } + private val _formatter = AtomicReference(DefaultMessageFormatter) + public var formatter: Formatter + get() = _formatter.value + set(value) { + _formatter.value = value + } } diff --git a/src/nativeMain/kotlin/mu/KotlinLoggingLevel.kt b/src/nativeMain/kotlin/mu/KotlinLoggingLevel.kt index c484160a..dd21c703 100644 --- a/src/nativeMain/kotlin/mu/KotlinLoggingLevel.kt +++ b/src/nativeMain/kotlin/mu/KotlinLoggingLevel.kt @@ -3,11 +3,11 @@ package mu import mu.KotlinLoggingConfiguration.logLevel public enum class KotlinLoggingLevel { - TRACE, - DEBUG, - INFO, - WARN, - ERROR + 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 index 435bfe32..87f8f10b 100644 --- a/src/nativeMain/kotlin/mu/Marker.kt +++ b/src/nativeMain/kotlin/mu/Marker.kt @@ -2,5 +2,5 @@ package mu public actual interface Marker { - public actual fun getName(): String + public actual fun getName(): String } diff --git a/src/nativeMain/kotlin/mu/internal/ErrorMessageProducer.kt b/src/nativeMain/kotlin/mu/internal/ErrorMessageProducer.kt index c7d1f5a2..32da3fba 100644 --- a/src/nativeMain/kotlin/mu/internal/ErrorMessageProducer.kt +++ b/src/nativeMain/kotlin/mu/internal/ErrorMessageProducer.kt @@ -1,5 +1,5 @@ package mu.internal public actual object ErrorMessageProducer { - public actual fun getErrorLog(e: Exception): String = "Log message invocation failed: $e" + 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/mu/internal/KLoggerLinux.kt index d2f0fd6d..c28a8745 100644 --- a/src/nativeMain/kotlin/mu/internal/KLoggerLinux.kt +++ b/src/nativeMain/kotlin/mu/internal/KLoggerLinux.kt @@ -8,103 +8,123 @@ import mu.KotlinLoggingLevel.* import mu.Marker import mu.isLoggingEnabled -internal class KLoggerLinux( - private val loggerName: String -) : KLogger { +internal class KLoggerLinux(private val loggerName: String) : KLogger { - override fun trace(msg: () -> Any?) = TRACE.logIfEnabled(msg, appender::trace) + override fun trace(msg: () -> Any?) = TRACE.logIfEnabled(msg, appender::trace) - override fun debug(msg: () -> Any?) = DEBUG.logIfEnabled(msg, appender::debug) + override fun debug(msg: () -> Any?) = DEBUG.logIfEnabled(msg, appender::debug) - override fun info(msg: () -> Any?) = INFO.logIfEnabled(msg, appender::info) + override fun info(msg: () -> Any?) = INFO.logIfEnabled(msg, appender::info) - override fun warn(msg: () -> Any?) = WARN.logIfEnabled(msg, appender::warn) + override fun warn(msg: () -> Any?) = WARN.logIfEnabled(msg, appender::warn) - override fun error(msg: () -> Any?) = ERROR.logIfEnabled(msg, appender::error) + override fun error(msg: () -> Any?) = ERROR.logIfEnabled(msg, appender::error) - override fun trace(t: Throwable?, msg: () -> Any?) = TRACE.logIfEnabled(msg, t, appender::trace) + override fun trace(t: Throwable?, msg: () -> Any?) = TRACE.logIfEnabled(msg, t, appender::trace) - override fun debug(t: Throwable?, msg: () -> Any?) = DEBUG.logIfEnabled(msg, t, appender::debug) + override fun debug(t: Throwable?, msg: () -> Any?) = DEBUG.logIfEnabled(msg, t, appender::debug) - override fun info(t: Throwable?, msg: () -> Any?) = INFO.logIfEnabled(msg, t, appender::info) + override fun info(t: Throwable?, msg: () -> Any?) = INFO.logIfEnabled(msg, t, appender::info) - override fun warn(t: Throwable?, msg: () -> Any?) = WARN.logIfEnabled(msg, t, appender::warn) + override fun warn(t: Throwable?, msg: () -> Any?) = WARN.logIfEnabled(msg, t, appender::warn) - override fun error(t: Throwable?, msg: () -> Any?) = ERROR.logIfEnabled(msg, t, appender::error) + override fun error(t: Throwable?, msg: () -> Any?) = ERROR.logIfEnabled(msg, t, appender::error) - override fun trace(marker: Marker?, msg: () -> Any?) = TRACE.logIfEnabled(marker, msg, appender::trace) + override fun trace(marker: Marker?, msg: () -> Any?) = + TRACE.logIfEnabled(marker, msg, appender::trace) - override fun debug(marker: Marker?, msg: () -> Any?) = DEBUG.logIfEnabled(marker, msg, appender::debug) + override fun debug(marker: Marker?, msg: () -> Any?) = + DEBUG.logIfEnabled(marker, msg, appender::debug) - override fun info(marker: Marker?, msg: () -> Any?) = INFO.logIfEnabled(marker, msg, appender::info) + override fun info(marker: Marker?, msg: () -> Any?) = + INFO.logIfEnabled(marker, msg, appender::info) - override fun warn(marker: Marker?, msg: () -> Any?) = WARN.logIfEnabled(marker, msg, appender::warn) + override fun warn(marker: Marker?, msg: () -> Any?) = + WARN.logIfEnabled(marker, msg, appender::warn) - override fun error(marker: Marker?, msg: () -> Any?) = ERROR.logIfEnabled(marker, msg, appender::error) + override fun error(marker: Marker?, msg: () -> Any?) = + ERROR.logIfEnabled(marker, msg, appender::error) - override fun trace(marker: Marker?, t: Throwable?, msg: () -> Any?) = - TRACE.logIfEnabled(marker, msg, t, appender::trace) + override fun trace(marker: Marker?, t: Throwable?, msg: () -> Any?) = + TRACE.logIfEnabled(marker, msg, t, appender::trace) - override fun debug(marker: Marker?, t: Throwable?, msg: () -> Any?) = - DEBUG.logIfEnabled(marker, msg, t, appender::debug) + override fun debug(marker: Marker?, t: Throwable?, msg: () -> Any?) = + DEBUG.logIfEnabled(marker, msg, t, appender::debug) - override fun info(marker: Marker?, t: Throwable?, msg: () -> Any?) = - INFO.logIfEnabled(marker, msg, t, appender::info) + override fun info(marker: Marker?, t: Throwable?, msg: () -> Any?) = + INFO.logIfEnabled(marker, msg, t, appender::info) - override fun warn(marker: Marker?, t: Throwable?, msg: () -> Any?) = - WARN.logIfEnabled(marker, msg, t, appender::warn) + override fun warn(marker: Marker?, t: Throwable?, msg: () -> Any?) = + WARN.logIfEnabled(marker, msg, t, appender::warn) - override fun error(marker: Marker?, t: Throwable?, msg: () -> Any?) = - ERROR.logIfEnabled(marker, msg, t, appender::error) + override fun error(marker: Marker?, t: Throwable?, msg: () -> Any?) = + ERROR.logIfEnabled(marker, msg, t, appender::error) - private fun KotlinLoggingLevel.logIfEnabled(msg: () -> Any?, logFunction: (String, String) -> Unit) { - if (isLoggingEnabled()) { - logFunction(loggerName, formatter.formatMessage(appender.includePrefix, this, loggerName, msg)) - } + private fun KotlinLoggingLevel.logIfEnabled( + msg: () -> Any?, + logFunction: (String, String) -> Unit + ) { + if (isLoggingEnabled()) { + logFunction( + loggerName, formatter.formatMessage(appender.includePrefix, this, loggerName, msg)) } - - private fun KotlinLoggingLevel.logIfEnabled(msg: () -> Any?, t: Throwable?, logFunction: (String, String) -> Unit) { - if (isLoggingEnabled()) { - logFunction(loggerName, formatter.formatMessage(appender.includePrefix, this, loggerName, t, msg)) - } + } + + private fun KotlinLoggingLevel.logIfEnabled( + msg: () -> Any?, + t: Throwable?, + logFunction: (String, String) -> Unit + ) { + if (isLoggingEnabled()) { + logFunction( + loggerName, formatter.formatMessage(appender.includePrefix, this, loggerName, t, msg)) } - - private fun KotlinLoggingLevel.logIfEnabled(marker: Marker?, msg: () -> Any?, logFunction: (String, String) -> Unit) { - if (isLoggingEnabled()) { - logFunction(loggerName, formatter.formatMessage(appender.includePrefix, this, loggerName, marker, msg)) - } + } + + private fun KotlinLoggingLevel.logIfEnabled( + marker: Marker?, + msg: () -> Any?, + logFunction: (String, String) -> Unit + ) { + if (isLoggingEnabled()) { + logFunction( + loggerName, + formatter.formatMessage(appender.includePrefix, this, loggerName, marker, msg)) } - - private fun KotlinLoggingLevel.logIfEnabled( - marker: Marker?, - msg: () -> Any?, - t: Throwable?, - logFunction: (String, String) -> Unit - ) { - if (isLoggingEnabled()) { - logFunction(loggerName, formatter.formatMessage(appender.includePrefix, this, loggerName, marker, t, msg)) - } + } + + private fun KotlinLoggingLevel.logIfEnabled( + marker: Marker?, + msg: () -> Any?, + t: Throwable?, + logFunction: (String, String) -> Unit + ) { + if (isLoggingEnabled()) { + logFunction( + loggerName, + formatter.formatMessage(appender.includePrefix, this, loggerName, marker, t, msg)) } + } - override fun entry(vararg argArray: Any?) { - TRACE.logIfEnabled({ "entry($argArray)" }, appender::trace) - } + override fun entry(vararg argArray: Any?) { + TRACE.logIfEnabled({ "entry($argArray)" }, appender::trace) + } - override fun exit() { - TRACE.logIfEnabled({ "exit()" }, appender::trace) - } + override fun exit() { + TRACE.logIfEnabled({ "exit()" }, appender::trace) + } - override fun exit(result: T): T { - TRACE.logIfEnabled({ "exit($result)" }, appender::trace) - return result - } + override fun exit(result: T): T { + TRACE.logIfEnabled({ "exit($result)" }, appender::trace) + return result + } - override fun throwing(throwable: T): T { - ERROR.logIfEnabled({ "throwing($throwable" }, throwable, appender::error) - return throwable - } + override fun throwing(throwable: T): T { + ERROR.logIfEnabled({ "throwing($throwable" }, throwable, appender::error) + return throwable + } - override fun catching(throwable: T) { - ERROR.logIfEnabled({ "catching($throwable" }, throwable, appender::error) - } + override fun catching(throwable: T) { + ERROR.logIfEnabled({ "catching($throwable" }, throwable, appender::error) + } } diff --git a/src/nativeMain/kotlin/mu/internal/MarkerNative.kt b/src/nativeMain/kotlin/mu/internal/MarkerNative.kt index 5f06e1f5..eb82e294 100644 --- a/src/nativeMain/kotlin/mu/internal/MarkerNative.kt +++ b/src/nativeMain/kotlin/mu/internal/MarkerNative.kt @@ -4,5 +4,5 @@ import mu.Marker internal class MarkerNative(private val name: String) : Marker { - override fun getName(): String = this.name + override fun getName(): String = this.name }