From bd0b8f7e739c226114917cc4f70c6dbab6757287 Mon Sep 17 00:00:00 2001 From: Ohad Shai Date: Thu, 13 Jul 2023 02:30:42 +0300 Subject: [PATCH 01/26] Deprecated method and class impl (#336) * add back deprecated methods in KLogger * add back deprecated KLogging * add deprecation messages --- .../io/github/oshai/kotlinlogging/KLogger.kt | 136 ++++++++++++------ .../slf4j/internal/LocationAwareKLogger.kt | 2 +- .../slf4j/internal/LocationIgnorantKLogger.kt | 2 +- .../slf4j/internal/Slf4jLogger.kt | 131 ++++++++++++++++- .../io/github/oshai/kotlinlogging/KLogging.kt | 42 ++++++ 5 files changed, 266 insertions(+), 47 deletions(-) create mode 100644 src/jvmMain/kotlin/io/github/oshai/kotlinlogging/KLogging.kt diff --git a/src/commonMain/kotlin/io/github/oshai/kotlinlogging/KLogger.kt b/src/commonMain/kotlin/io/github/oshai/kotlinlogging/KLogger.kt index 2d8671e3..d8009c61 100644 --- a/src/commonMain/kotlin/io/github/oshai/kotlinlogging/KLogger.kt +++ b/src/commonMain/kotlin/io/github/oshai/kotlinlogging/KLogger.kt @@ -1,3 +1,5 @@ +@file:Suppress("MoveLambdaOutsideParentheses") + package io.github.oshai.kotlinlogging import io.github.oshai.kotlinlogging.internal.toStringSafe @@ -280,7 +282,8 @@ public interface KLogger { * * @param msg the message string to be logged */ - @Deprecated("Use trace {} instead") public fun trace(msg: String?): Unit = trace { msg } + @Deprecated("Use trace {} instead", replaceWith = ReplaceWith("trace { \"\$msg\"}")) + public fun trace(msg: String?): Unit = trace { msg } /** * Log a message at the TRACE level according to the specified msg and argument. @@ -290,7 +293,8 @@ public interface KLogger { * @param msg the msg string * @param arg the argument */ - @Deprecated("Use trace {} instead") public fun trace(msg: String?, arg: Any?): Unit = TODO() + @Deprecated("Use trace {} instead", replaceWith = ReplaceWith("trace { \"\$msg \$arg\"}")) + public fun trace(msg: String?, arg: Any?): Unit = TODO() /** * Log a message at the TRACE level according to the specified msg and arguments. @@ -301,7 +305,7 @@ public interface KLogger { * @param arg1 the first argument * @param arg2 the second argument */ - @Deprecated("Use trace {} instead") + @Deprecated("Use trace {} instead", replaceWith = ReplaceWith("trace { \"\$msg \$arg1 \$arg2\"}")) public fun trace(msg: String?, arg1: Any?, arg2: Any?): Unit = TODO() /** @@ -316,7 +320,7 @@ public interface KLogger { * @param msg the msg string * @param arguments a list of 3 or more arguments */ - @Deprecated("Use trace {} instead") + @Deprecated("Use trace {} instead", replaceWith = ReplaceWith("trace { \"\$msg \$arguments\"}")) public fun trace(msg: String?, vararg arguments: Any?): Unit = TODO() /** @@ -325,7 +329,7 @@ public interface KLogger { * @param msg the message accompanying the exception * @param t the exception (throwable) to log */ - @Deprecated("Use trace {} instead") + @Deprecated("Use trace {} instead", replaceWith = ReplaceWith("trace(t) { \"\$msg\"}")) public fun trace(msg: String?, t: Throwable?): Unit = trace(t as Throwable, null, { msg }) /** @@ -334,7 +338,7 @@ public interface KLogger { * @param marker the marker data specific to this log statement * @param msg the message string to be logged */ - @Deprecated("Use trace {} instead") + @Deprecated("Use trace {} instead", replaceWith = ReplaceWith("trace(marker) { \"\$msg\"}")) public fun trace(marker: Marker?, msg: String?): Unit = trace(null as Throwable?, marker, { msg }) /** @@ -345,7 +349,7 @@ public interface KLogger { * @param msg the msg string * @param arg the argument */ - @Deprecated("Use trace {} instead") + @Deprecated("Use trace {} instead", replaceWith = ReplaceWith("trace(marker) { \"\$msg \$arg\"}")) public fun trace(marker: Marker?, msg: String?, arg: Any?): Unit = TODO() /** @@ -357,7 +361,10 @@ public interface KLogger { * @param arg1 the first argument * @param arg2 the second argument */ - @Deprecated("Use trace {} instead") + @Deprecated( + "Use trace {} instead", + replaceWith = ReplaceWith("trace(marker) { \"\$msg \$arg1 \$arg2\"}") + ) public fun trace(marker: Marker?, msg: String?, arg1: Any?, arg2: Any?): Unit = TODO() /** @@ -368,7 +375,10 @@ public interface KLogger { * @param msg the msg string * @param arguments an array of arguments */ - @Deprecated("Use trace {} instead") + @Deprecated( + "Use trace {} instead", + replaceWith = ReplaceWith("trace(marker) { \"\$msg \$arguments\"}") + ) public fun trace(marker: Marker?, msg: String?, vararg arguments: Any?): Unit = TODO() /** @@ -379,7 +389,7 @@ public interface KLogger { * @param msg the message accompanying the exception * @param t the exception (throwable) to log */ - @Deprecated("Use trace {} instead") + @Deprecated("Use trace {} instead", replaceWith = ReplaceWith("trace(t, marker) { \"\$msg\"}")) public fun trace(marker: Marker?, msg: String?, t: Throwable?): Unit = trace(t as Throwable, marker, { msg }) @@ -388,7 +398,8 @@ public interface KLogger { * * @param msg the message string to be logged */ - @Deprecated("Use debug {} instead") public fun debug(msg: String?): Unit = debug { msg } + @Deprecated("Use debug {} instead", replaceWith = ReplaceWith("debug { \"\$msg\"}")) + public fun debug(msg: String?): Unit = debug { msg } /** * Log a message at the DEBUG level according to the specified msg and argument. @@ -398,7 +409,8 @@ public interface KLogger { * @param msg the msg string * @param arg the argument */ - @Deprecated("Use debug {} instead") public fun debug(msg: String?, arg: Any?): Unit = TODO() + @Deprecated("Use debug {} instead", replaceWith = ReplaceWith("debug { \"\$msg \$arg\"}")) + public fun debug(msg: String?, arg: Any?): Unit = TODO() /** * Log a message at the DEBUG level according to the specified msg and arguments. @@ -409,7 +421,7 @@ public interface KLogger { * @param arg1 the first argument * @param arg2 the second argument */ - @Deprecated("Use debug {} instead") + @Deprecated("Use debug {} instead", replaceWith = ReplaceWith("debug { \"\$msg \$arg1 \$arg2\"}")) public fun debug(msg: String?, arg1: Any?, arg2: Any?): Unit = TODO() /** @@ -433,7 +445,7 @@ public interface KLogger { * @param msg the message accompanying the exception * @param t the exception (throwable) to log */ - @Deprecated("Use debug {} instead") + @Deprecated("Use debug {} instead", replaceWith = ReplaceWith("debug(t) { \"\$msg\"}")) public fun debug(msg: String?, t: Throwable?): Unit = debug(t as Throwable, null, { msg }) /** @@ -442,7 +454,7 @@ public interface KLogger { * @param marker the marker data specific to this log statement * @param msg the message string to be logged */ - @Deprecated("Use debug {} instead") + @Deprecated("Use debug {} instead", replaceWith = ReplaceWith("debug(marker) { \"\$msg\"}")) public fun debug(marker: Marker?, msg: String?): Unit = debug(null as Throwable?, marker, { msg }) /** @@ -453,7 +465,7 @@ public interface KLogger { * @param msg the msg string * @param arg the argument */ - @Deprecated("Use debug {} instead") + @Deprecated("Use debug {} instead", replaceWith = ReplaceWith("debug(marker) { \"\$msg \$arg\"}")) public fun debug(marker: Marker?, msg: String?, arg: Any?): Unit = TODO() /** @@ -465,7 +477,10 @@ public interface KLogger { * @param arg1 the first argument * @param arg2 the second argument */ - @Deprecated("Use debug {} instead") + @Deprecated( + "Use debug {} instead", + replaceWith = ReplaceWith("debug(marker) { \"\$msg \$arg1 \$arg2\"}") + ) public fun debug(marker: Marker?, msg: String?, arg1: Any?, arg2: Any?): Unit = TODO() /** @@ -476,7 +491,10 @@ public interface KLogger { * @param msg the msg string * @param arguments a list of 3 or more arguments */ - @Deprecated("Use debug {} instead") + @Deprecated( + "Use debug {} instead", + replaceWith = ReplaceWith("debug(marker) { \"\$msg \$arguments\"}") + ) public fun debug(marker: Marker?, msg: String?, vararg arguments: Any?): Unit = TODO() /** @@ -487,7 +505,7 @@ public interface KLogger { * @param msg the message accompanying the exception * @param t the exception (throwable) to log */ - @Deprecated("Use debug {} instead") + @Deprecated("Use debug {} instead", replaceWith = ReplaceWith("debug(t, marker) { \"\$msg\"}")) public fun debug(marker: Marker?, msg: String?, t: Throwable?): Unit = debug(t as Throwable, marker, { msg }) @@ -506,7 +524,8 @@ public interface KLogger { * @param msg the msg string * @param arg the argument */ - @Deprecated("Use info {} instead") public fun info(msg: String?, arg: Any?): Unit = TODO() + @Deprecated("Use info {} instead", replaceWith = ReplaceWith("info { \"\$msg \$arg\"}")) + public fun info(msg: String?, arg: Any?): Unit = TODO() /** * Log a message at the INFO level according to the specified msg and arguments. @@ -517,7 +536,7 @@ public interface KLogger { * @param arg1 the first argument * @param arg2 the second argument */ - @Deprecated("Use info {} instead") + @Deprecated("Use info {} instead", replaceWith = ReplaceWith("info { \"\$msg \$arg1 \$arg2\"}")) public fun info(msg: String?, arg1: Any?, arg2: Any?): Unit = TODO() /** @@ -531,7 +550,7 @@ public interface KLogger { * @param msg the msg string * @param arguments a list of 3 or more arguments */ - @Deprecated("Use info {} instead") + @Deprecated("Use info {} instead", replaceWith = ReplaceWith("info { \"\$msg \$arguments\"}")) public fun info(msg: String?, vararg arguments: Any?): Unit = TODO() /** @@ -540,7 +559,7 @@ public interface KLogger { * @param msg the message accompanying the exception * @param t the exception (throwable) to log */ - @Deprecated("Use info {} instead") + @Deprecated("Use info {} instead", replaceWith = ReplaceWith("info(t) { \"\$msg\"}")) public fun info(msg: String?, t: Throwable?): Unit = info(t as Throwable, null, { msg }) /** @@ -549,7 +568,7 @@ public interface KLogger { * @param marker The marker specific to this log statement * @param msg the message string to be logged */ - @Deprecated("Use info {} instead") + @Deprecated("Use info {} instead", replaceWith = ReplaceWith("info(marker) { \"\$msg\"}")) public fun info(marker: Marker?, msg: String?): Unit = info(null as Throwable?, marker, { msg }) /** @@ -560,7 +579,7 @@ public interface KLogger { * @param msg the msg string * @param arg the argument */ - @Deprecated("Use info {} instead") + @Deprecated("Use info {} instead", replaceWith = ReplaceWith("info(marker) { \"\$msg \$arg\"}")) public fun info(marker: Marker?, msg: String?, arg: Any?): Unit = TODO() /** @@ -572,7 +591,10 @@ public interface KLogger { * @param arg1 the first argument * @param arg2 the second argument */ - @Deprecated("Use info {} instead") + @Deprecated( + "Use info {} instead", + replaceWith = ReplaceWith("info(marker) { \"\$msg \$arg1 \$arg2\"}") + ) public fun info(marker: Marker?, msg: String?, arg1: Any?, arg2: Any?): Unit = TODO() /** @@ -583,7 +605,10 @@ public interface KLogger { * @param msg the msg string * @param arguments a list of 3 or more arguments */ - @Deprecated("Use info {} instead") + @Deprecated( + "Use info {} instead", + replaceWith = ReplaceWith("info(marker) { \"\$msg \$arguments\"}") + ) public fun info(marker: Marker?, msg: String?, vararg arguments: Any?): Unit = TODO() /** @@ -594,7 +619,7 @@ public interface KLogger { * @param msg the message accompanying the exception * @param t the exception (throwable) to log */ - @Deprecated("Use info {} instead") + @Deprecated("Use info {} instead", replaceWith = ReplaceWith("info(t, marker) { \"\$msg\"}")) public fun info(marker: Marker?, msg: String?, t: Throwable?): Unit = info(t as Throwable, marker, { msg }) @@ -613,7 +638,8 @@ public interface KLogger { * @param msg the msg string * @param arg the argument */ - @Deprecated("Use warn {} instead") public fun warn(msg: String?, arg: Any?): Unit = TODO() + @Deprecated("Use warn {} instead", replaceWith = ReplaceWith("warn { \"\$msg \$arg\"}")) + public fun warn(msg: String?, arg: Any?): Unit = TODO() /** * Log a message at the WARN level according to the specified msg and arguments. @@ -626,7 +652,7 @@ public interface KLogger { * @param msg the msg string * @param arguments a list of 3 or more arguments */ - @Deprecated("Use warn {} instead") + @Deprecated("Use warn {} instead", replaceWith = ReplaceWith("warn { \"\$msg \$arguments\"}")) public fun warn(msg: String?, vararg arguments: Any?): Unit = TODO() /** @@ -638,7 +664,7 @@ public interface KLogger { * @param arg1 the first argument * @param arg2 the second argument */ - @Deprecated("Use warn {} instead") + @Deprecated("Use warn {} instead", replaceWith = ReplaceWith("warn { \"\$msg \$arg1 \$arg2\"}")) public fun warn(msg: String?, arg1: Any?, arg2: Any?): Unit = TODO() /** @@ -647,7 +673,7 @@ public interface KLogger { * @param msg the message accompanying the exception * @param t the exception (throwable) to log */ - @Deprecated("Use warn {} instead") + @Deprecated("Use warn {} instead", replaceWith = ReplaceWith("warn(t) { \"\$msg\"}")) public fun warn(msg: String?, t: Throwable?): Unit = warn(t as Throwable, null, { msg }) /** @@ -656,7 +682,7 @@ public interface KLogger { * @param marker The marker specific to this log statement * @param msg the message string to be logged */ - @Deprecated("Use warn {} instead") + @Deprecated("Use warn {} instead", replaceWith = ReplaceWith("warn(marker) { \"\$msg\"}")) public fun warn(marker: Marker?, msg: String?): Unit = warn(null as Throwable?, marker, { msg }) /** @@ -667,7 +693,7 @@ public interface KLogger { * @param msg the msg string * @param arg the argument */ - @Deprecated("Use warn {} instead") + @Deprecated("Use warn {} instead", replaceWith = ReplaceWith("warn(marker) { \"\$msg \$arg\"}")) public fun warn(marker: Marker?, msg: String?, arg: Any?): Unit = TODO() /** @@ -679,6 +705,10 @@ public interface KLogger { * @param arg1 the first argument * @param arg2 the second argument */ + @Deprecated( + "Use warn {} instead", + replaceWith = ReplaceWith("warn(marker) { \"\$msg \$arg1 \$arg2\"}") + ) public fun warn(marker: Marker?, msg: String?, arg1: Any?, arg2: Any?): Unit = TODO() /** @@ -689,7 +719,10 @@ public interface KLogger { * @param msg the msg string * @param arguments a list of 3 or more arguments */ - @Deprecated("Use warn {} instead") + @Deprecated( + "Use warn {} instead", + replaceWith = ReplaceWith("warn(marker) { \"\$msg \$arguments\"}") + ) public fun warn(marker: Marker?, msg: String?, vararg arguments: Any?): Unit = TODO() /** @@ -700,7 +733,7 @@ public interface KLogger { * @param msg the message accompanying the exception * @param t the exception (throwable) to log */ - @Deprecated("Use warn {} instead") + @Deprecated("Use warn {} instead", replaceWith = ReplaceWith("warn(t, marker) { \"\$msg\"}")) public fun warn(marker: Marker?, msg: String?, t: Throwable?): Unit = warn(t as Throwable, marker, { msg }) @@ -709,7 +742,8 @@ public interface KLogger { * * @param msg the message string to be logged */ - @Deprecated("Use error {} instead") public fun error(msg: String?): Unit = error { msg } + @Deprecated("Use error {} instead", replaceWith = ReplaceWith("error { \"\$msg\"}")) + public fun error(msg: String?): Unit = error { msg } /** * Log a message at the ERROR level according to the specified msg and argument. @@ -719,7 +753,8 @@ public interface KLogger { * @param msg the msg string * @param arg the argument */ - @Deprecated("Use error {} instead") public fun error(msg: String?, arg: Any?): Unit = TODO() + @Deprecated("Use error {} instead", replaceWith = ReplaceWith("error { \"\$msg \$arg\"}")) + public fun error(msg: String?, arg: Any?): Unit = TODO() /** * Log a message at the ERROR level according to the specified msg and arguments. @@ -730,7 +765,7 @@ public interface KLogger { * @param arg1 the first argument * @param arg2 the second argument */ - @Deprecated("Use error {} instead") + @Deprecated("Use error {} instead", replaceWith = ReplaceWith("error { \"\$msg \$arg1 \$arg2\"}")) public fun error(msg: String?, arg1: Any?, arg2: Any?): Unit = TODO() /** @@ -745,7 +780,7 @@ public interface KLogger { * @param msg the msg string * @param arguments a list of 3 or more arguments */ - @Deprecated("Use error {} instead") + @Deprecated("Use error {} instead", replaceWith = ReplaceWith("error { \"\$msg \$arguments\"}")) public fun error(msg: String?, vararg arguments: Any?): Unit = TODO() /** @@ -754,7 +789,7 @@ public interface KLogger { * @param msg the message accompanying the exception * @param t the exception (throwable) to log */ - @Deprecated("Use error(t){} instead") + @Deprecated("Use error(t){} instead", replaceWith = ReplaceWith("error(t) { \"\$msg\"}")) public fun error(msg: String?, t: Throwable?): Unit = error(t, null) { msg } /** @@ -763,7 +798,10 @@ public interface KLogger { * @param marker The marker specific to this log statement * @param msg the message string to be logged */ - @Deprecated("Use error(marker){} instead") + @Deprecated( + "Use error(marker){} instead", + replaceWith = ReplaceWith("error(marker) { \"\$msg\"}") + ) public fun error(marker: Marker?, msg: String?): Unit = error(null as Throwable?, marker) { msg } /** @@ -774,6 +812,10 @@ public interface KLogger { * @param msg the msg string * @param arg the argument */ + @Deprecated( + "Use error(marker){} instead", + replaceWith = ReplaceWith("error(marker) { \"\$msg \$arg \"}") + ) public fun error(marker: Marker?, msg: String?, arg: Any?): Unit = TODO() /** @@ -785,7 +827,10 @@ public interface KLogger { * @param arg1 the first argument * @param arg2 the second argument */ - @Deprecated("Use error(marker){} instead") + @Deprecated( + "Use error(marker){} instead", + replaceWith = ReplaceWith("error(marker) { \"\$msg \$arg1 \$arg2\"}") + ) public fun error(marker: Marker?, msg: String?, arg1: Any?, arg2: Any?): Unit = TODO() /** @@ -796,7 +841,10 @@ public interface KLogger { * @param msg the msg string * @param arguments a list of 3 or more arguments */ - @Deprecated("Use error(marker){} instead") + @Deprecated( + "Use error(marker){} instead", + replaceWith = ReplaceWith("error(marker) { \"\$msg \$arguments\"}") + ) public fun error(marker: Marker?, msg: String?, vararg arguments: Any?): Unit = TODO() @Deprecated("Use error instead", ReplaceWith("error(t, marker, msg)")) diff --git a/src/javaMain/kotlin/io/github/oshai/kotlinlogging/slf4j/internal/LocationAwareKLogger.kt b/src/javaMain/kotlin/io/github/oshai/kotlinlogging/slf4j/internal/LocationAwareKLogger.kt index e8967704..3dbeec27 100644 --- a/src/javaMain/kotlin/io/github/oshai/kotlinlogging/slf4j/internal/LocationAwareKLogger.kt +++ b/src/javaMain/kotlin/io/github/oshai/kotlinlogging/slf4j/internal/LocationAwareKLogger.kt @@ -17,7 +17,7 @@ import org.slf4j.spi.LocationAwareLogger * correct fully qualified class name. */ internal class LocationAwareKLogger(override val underlyingLogger: LocationAwareLogger) : - KLogger, DelegatingKLogger, Slf4jLogger() { + KLogger, DelegatingKLogger, Slf4jLogger() { override val name: String get() = underlyingLogger.name diff --git a/src/javaMain/kotlin/io/github/oshai/kotlinlogging/slf4j/internal/LocationIgnorantKLogger.kt b/src/javaMain/kotlin/io/github/oshai/kotlinlogging/slf4j/internal/LocationIgnorantKLogger.kt index e1f853c0..c1115c81 100644 --- a/src/javaMain/kotlin/io/github/oshai/kotlinlogging/slf4j/internal/LocationIgnorantKLogger.kt +++ b/src/javaMain/kotlin/io/github/oshai/kotlinlogging/slf4j/internal/LocationIgnorantKLogger.kt @@ -14,7 +14,7 @@ import org.slf4j.Logger * methods */ internal class LocationIgnorantKLogger(override val underlyingLogger: Logger) : - KLogger, DelegatingKLogger, Slf4jLogger() { + KLogger, DelegatingKLogger, Slf4jLogger() { override val name: String get() = underlyingLogger.name diff --git a/src/javaMain/kotlin/io/github/oshai/kotlinlogging/slf4j/internal/Slf4jLogger.kt b/src/javaMain/kotlin/io/github/oshai/kotlinlogging/slf4j/internal/Slf4jLogger.kt index 227c302c..909fcdd5 100644 --- a/src/javaMain/kotlin/io/github/oshai/kotlinlogging/slf4j/internal/Slf4jLogger.kt +++ b/src/javaMain/kotlin/io/github/oshai/kotlinlogging/slf4j/internal/Slf4jLogger.kt @@ -1,12 +1,13 @@ package io.github.oshai.kotlinlogging.slf4j.internal +import io.github.oshai.kotlinlogging.DelegatingKLogger import io.github.oshai.kotlinlogging.KLogger import io.github.oshai.kotlinlogging.Level import io.github.oshai.kotlinlogging.Marker import io.github.oshai.kotlinlogging.slf4j.toSlf4j import org.slf4j.Logger -public abstract class Slf4jLogger : KLogger { +public abstract class Slf4jLogger : KLogger, DelegatingKLogger { // we don't move more methods to here because if it will appear on stacktrace // it will break fqcn for class name in location aware loggers @@ -26,4 +27,132 @@ public abstract class Slf4jLogger : KLogger { Level.OFF -> false } } + + /// + /// The methods below are deprecated and will be removed in the future + /// + + @Deprecated("Use trace {} instead", replaceWith = ReplaceWith("trace { \"\$msg \$arg\"}")) + public override fun trace(msg: String?, arg: Any?): Unit = underlyingLogger.trace(msg, arg) + + @Deprecated("Use trace {} instead", replaceWith = ReplaceWith("trace { \"\$msg \$arg1 \$arg2\"}")) + public override fun trace(msg: String?, arg1: Any?, arg2: Any?): Unit = + underlyingLogger.trace(msg, arg1, arg2) + + @Deprecated("Use trace {} instead", replaceWith = ReplaceWith("trace { \"\$msg \$arguments\"}")) + public override fun trace(msg: String?, vararg arguments: Any?): Unit = + underlyingLogger.trace(msg, *arguments) + + @Deprecated("Use trace {} instead", replaceWith = ReplaceWith("trace { \"\$msg \$arg\"}")) + public override fun trace(marker: Marker?, msg: String?, arg: Any?): Unit = + underlyingLogger.trace(marker?.toSlf4j(), msg, arg) + + @Deprecated("Use trace {} instead", replaceWith = ReplaceWith("trace { \"\$msg \$arg1 \$arg2\"}")) + public override fun trace(marker: Marker?, msg: String?, arg1: Any?, arg2: Any?): Unit = + underlyingLogger.trace(marker?.toSlf4j(), msg, arg1, arg2) + + @Deprecated("Use trace {} instead", replaceWith = ReplaceWith("trace { \"\$msg \$arguments\"}")) + public override fun trace(marker: Marker?, msg: String?, vararg arguments: Any?): Unit = + underlyingLogger.trace(marker?.toSlf4j(), msg, *arguments) + + @Deprecated("Use debug {} instead", replaceWith = ReplaceWith("debug { \"\$msg \$arg\"}")) + public override fun debug(msg: String?, arg: Any?): Unit = underlyingLogger.debug(msg, arg) + + @Deprecated("Use debug {} instead", replaceWith = ReplaceWith("debug { \"\$msg \$arg1 \$arg2\"}")) + public override fun debug(msg: String?, arg1: Any?, arg2: Any?): Unit = + underlyingLogger.debug(msg, arg1, arg2) + + @Deprecated("Use debug {} instead", replaceWith = ReplaceWith("debug { \"\$msg \$arguments\"}")) + public override fun debug(msg: String?, vararg arguments: Any?): Unit = + underlyingLogger.debug(msg, *arguments) + + @Deprecated("Use debug {} instead", replaceWith = ReplaceWith("debug { \"\$msg \$arg\"}")) + public override fun debug(marker: Marker?, msg: String?, arg: Any?): Unit = + underlyingLogger.debug(marker?.toSlf4j(), msg, arg) + + @Deprecated("Use debug {} instead", replaceWith = ReplaceWith("debug { \"\$msg \$arg1 \$arg2\"}")) + public override fun debug(marker: Marker?, msg: String?, arg1: Any?, arg2: Any?): Unit = + underlyingLogger.debug(marker?.toSlf4j(), msg, arg1, arg2) + + @Deprecated("Use debug {} instead", replaceWith = ReplaceWith("debug { \"\$msg \$arguments\"}")) + public override fun debug(marker: Marker?, msg: String?, vararg arguments: Any?): Unit = + underlyingLogger.debug(marker?.toSlf4j(), msg, *arguments) + + @Deprecated("Use info {} instead", replaceWith = ReplaceWith("info { \"\$msg \$arg\"}")) + public override fun info(msg: String?, arg: Any?): Unit = underlyingLogger.info(msg, arg) + + @Deprecated("Use info {} instead", replaceWith = ReplaceWith("info { \"\$msg \$arg1 \$arg2\"}")) + public override fun info(msg: String?, arg1: Any?, arg2: Any?): Unit = + underlyingLogger.info(msg, arg1, arg2) + + @Deprecated("Use info {} instead", replaceWith = ReplaceWith("info { \"\$msg \$arguments\"}")) + public override fun info(msg: String?, vararg arguments: Any?): Unit = + underlyingLogger.info(msg, *arguments) + + @Deprecated("Use info {} instead", replaceWith = ReplaceWith("info { \"\$msg \$arg\"}")) + public override fun info(marker: Marker?, msg: String?, arg: Any?): Unit = + underlyingLogger.info(marker?.toSlf4j(), msg, arg) + + @Deprecated("Use info {} instead", replaceWith = ReplaceWith("info { \"\$msg \$arg1 \$arg2\"}")) + public override fun info(marker: Marker?, msg: String?, arg1: Any?, arg2: Any?): Unit = + underlyingLogger.info(marker?.toSlf4j(), msg, arg1, arg2) + + @Deprecated("Use info {} instead", replaceWith = ReplaceWith("info { \"\$msg \$arguments\"}")) + public override fun info(marker: Marker?, msg: String?, vararg arguments: Any?): Unit = + underlyingLogger.info(marker?.toSlf4j(), msg, *arguments) + + @Deprecated("Use warn {} instead", replaceWith = ReplaceWith("warn { \"\$msg \$arg\"}")) + public override fun warn(msg: String?, arg: Any?): Unit = underlyingLogger.warn(msg, arg) + + @Deprecated("Use warn {} instead", replaceWith = ReplaceWith("warn { \"\$msg \$arg1 \$arg2\"}")) + public override fun warn(msg: String?, vararg arguments: Any?): Unit = + underlyingLogger.warn(msg, *arguments) + + @Deprecated("Use warn {} instead", replaceWith = ReplaceWith("warn { \"\$msg \$arg1 \$arg2\"}")) + public override fun warn(msg: String?, arg1: Any?, arg2: Any?): Unit = + underlyingLogger.warn(msg, arg1, arg2) + + @Deprecated("Use warn {} instead", replaceWith = ReplaceWith("warn { \"\$msg \$arg\"}")) + public override fun warn(marker: Marker?, msg: String?, arg: Any?): Unit = + underlyingLogger.warn(marker?.toSlf4j(), msg, arg) + + @Deprecated("Use warn {} instead", replaceWith = ReplaceWith("warn { \"\$msg \$arg1 \$arg2\"}")) + public override fun warn(marker: Marker?, msg: String?, arg1: Any?, arg2: Any?): Unit = + underlyingLogger.warn(marker?.toSlf4j(), msg, arg1, arg2) + + @Deprecated("Use warn {} instead", replaceWith = ReplaceWith("warn { \"\$msg \$arguments\"}")) + public override fun warn(marker: Marker?, msg: String?, vararg arguments: Any?): Unit = + underlyingLogger.warn(marker?.toSlf4j(), msg, *arguments) + + @Deprecated("Use error {} instead", replaceWith = ReplaceWith("error { \"\$msg \$arg\"}")) + public override fun error(msg: String?, arg: Any?): Unit = underlyingLogger.error(msg, arg) + + @Deprecated("Use error {} instead", replaceWith = ReplaceWith("error { \"\$msg \$arg1 \$arg2\"}")) + public override fun error(msg: String?, arg1: Any?, arg2: Any?): Unit = + underlyingLogger.error(msg, arg1, arg2) + + @Deprecated("Use error {} instead", replaceWith = ReplaceWith("error { \"\$msg \$arguments\"}")) + public override fun error(msg: String?, vararg arguments: Any?): Unit = + underlyingLogger.error(msg, *arguments) + + @Deprecated( + "Use error(marker){} instead", + replaceWith = ReplaceWith("error(marker){ \"\$msg \$arg\"}") + ) + public override fun error(marker: Marker?, msg: String?, arg: Any?): Unit = + underlyingLogger.error(marker?.toSlf4j(), msg, arg) + + @Deprecated( + "Use error(marker){} instead", + replaceWith = ReplaceWith("error(marker){ \"\$msg \$arg1 \$arg2\"}") + ) + public override fun error(marker: Marker?, msg: String?, arg1: Any?, arg2: Any?): Unit = + underlyingLogger.error(marker?.toSlf4j(), msg, arg1, arg2) + + @Deprecated( + "Use error(marker){} instead", + replaceWith = ReplaceWith("error(marker){ \"\$msg \$arguments\"}") + ) + public override fun error(marker: Marker?, msg: String?, vararg arguments: Any?): Unit = + underlyingLogger.error(marker?.toSlf4j(), msg, *arguments) } diff --git a/src/jvmMain/kotlin/io/github/oshai/kotlinlogging/KLogging.kt b/src/jvmMain/kotlin/io/github/oshai/kotlinlogging/KLogging.kt new file mode 100644 index 00000000..27091edd --- /dev/null +++ b/src/jvmMain/kotlin/io/github/oshai/kotlinlogging/KLogging.kt @@ -0,0 +1,42 @@ +package io.github.oshai.kotlinlogging + +import io.github.oshai.kotlinlogging.internal.KLoggerFactory + +/** + * A class with logging capabilities usage example: + * ``` + * class ClassWithLogging { + * companion object: KLogging() + * fun test() { + * logger.info{"test ClassWithLogging"} + * } + * } + * ``` + */ +@Deprecated("Use KLogger instead", ReplaceWith("KLogger", "io.github.oshai.kotlinlogging.KLogger")) +public open class KLogging : KLoggable { + override val logger: KLogger = logger() +} + +/** A class with logging capabilities and explicit logger name */ +@Deprecated("Use KLogger instead", ReplaceWith("KLogger", "io.github.oshai.kotlinlogging.KLogger")) +public open class NamedKLogging(name: String) : KLoggable { + override val logger: KLogger = logger(name) +} + +/** + * An interface representing class with logging capabilities implemented using a logger obtain a + * logger with logger() method + */ +@Deprecated("Use KLogger instead", ReplaceWith("KLogger", "io.github.oshai.kotlinlogging.KLogger")) +public interface KLoggable { + + /** The member that performs the actual logging */ + public val logger: KLogger + + /** get logger for the class */ + public fun logger(): KLogger = KLoggerFactory.logger(this::class.java.name) + + /** get logger by explicit name */ + public fun logger(name: String): KLogger = KLoggerFactory.logger(name) +} From a7d4a4a0497b5ef5f3db7276190f443e7cdefac7 Mon Sep 17 00:00:00 2001 From: oshai Date: Thu, 13 Jul 2023 02:32:31 +0300 Subject: [PATCH 02/26] bump version to 5.0.0-beta-05 --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index 325441ab..6f6157ac 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -17,7 +17,7 @@ plugins { apply("versions.gradle.kts") group = "io.github.oshai" -version = "5.0.0-beta-04" +version = "5.0.0-beta-05" repositories { gradlePluginPortal() From 0db6882076cf5ff6e0ab857516108924701c40bf Mon Sep 17 00:00:00 2001 From: oshai Date: Thu, 13 Jul 2023 10:35:31 +0300 Subject: [PATCH 03/26] update docs for v.5 --- ChangeLog-old.md | 267 ++++++++++++++++++++++++++++++++++++++++++++ ChangeLog.md | 284 +++++++++-------------------------------------- README.md | 11 +- 3 files changed, 326 insertions(+), 236 deletions(-) create mode 100644 ChangeLog-old.md diff --git a/ChangeLog-old.md b/ChangeLog-old.md new file mode 100644 index 00000000..2d128dbb --- /dev/null +++ b/ChangeLog-old.md @@ -0,0 +1,267 @@ + +# For full changelog see github [releases page](https://github.com/oshai/kotlin-logging/releases) +# For the new changelog see github [ChangeLog.md](https://github.com/oshai/kotlin-logging/ChangeLog.md) + +# 2.1.20 + +* Same as `2.1.17`. + +# 2.1.17 + +* Upgrade log4j to 2.16.0 [#211](https://github.com/oshai/kotlin-logging/pull/211) [#207](https://github.com/oshai/kotlin-logging/pull/207). +* Upgrade dokka to 1.6 [#209](https://github.com/oshai/kotlin-logging/pull/209). +* Fix detekt warnings [#203](https://github.com/oshai/kotlin-logging/pull/203). +* Upgrade to junit 5 [#204](https://github.com/oshai/kotlin-logging/pull/204). + +# 2.1.15 + +* Add support for mingw (windows) and osx. + +# 2.1.14 + +* Move to github actions release. + +# 2.0.12 + +* added the license to all jar files [#191](https://github.com/oshai/kotlin-logging/pull/191. + +# 2.0.11 + +* Fixed losing previous values in MDC [#187](https://github.com/oshai/kotlin-logging/pull/187). + +# 2.0.10 + +* upgrade kotlin to 1.5 [#175](https://github.com/oshai/kotlin-logging/pull/175) +* unwrapCompanionClass fails to unwrap private companions when on kotlin 1.4+ [#182](https://github.com/oshai/kotlin-logging/issues/182). + +# 2.0.8 + +* Publish to maven central directly [#177](https://github.com/oshai/kotlin-logging/issues/177). + +# 2.0.7 + +* Support optional/nullable values for MDC [#172](https://github.com/oshai/kotlin-logging/issues/172). + +# 2.0.6 + +* Same as `2.0.5`. + +# 2.0.5 + +* Upgrade Kotlin to 1.4.31. + +# 2.0.4 + +* When an error occurs in Log message invocation then log it as an ERROR [#160](https://github.com/oshai/kotlin-logging/issues/160). + +# 2.0.3 + +* Fix Bintray versions display [#152](https://github.com/oshai/kotlin-logging/issues/152). + +# 2.0.2 + +* Build refactor and bintray plugin replacement [#145](https://github.com/oshai/kotlin-logging/pull/145). +* Support JS-IR backend [#139](https://github.com/oshai/kotlin-logging/pull/139). +* Use linux code for linux/macos/mingw targets [#131](https://github.com/oshai/kotlin-logging/pull/131). +* Upgrade to Kotlin 1.4.10 [#137](https://github.com/oshai/kotlin-logging/pull/137). +* Add explicit API in strict mode [#124](https://github.com/oshai/kotlin-logging/issues/124). + +# 2.X changes from 1.X + +The main incompatible change is in the artifact names. In version `1.x` the jvm artifact is called `kotlin-logging` while in version `2.x` it's called `kotlin-logging-jvm` to comply with the multiplatform schema. In addition, version 2.x supports only Kotlin >= 1.4. + +Therefore, for jvm library owners it is still recommended to use 1.x, as for the rest of the use cases 2.x is recommended. + + +# 1.12.5 + +* Fix Kotlin-logging version 1.12.0 is missing .module file in Maven artifact [#163](https://github.com/oshai/kotlin-logging/pull/163). + +# Versions 1.12.1 - 1.12.4 are obselete + +* Break versions due to kotlin upgrade, see [#170](https://github.com/oshai/kotlin-logging/issues/170). + +# 1.12.0 + +* Upgrade to Kotlin 1.4.10 [#148](https://github.com/oshai/kotlin-logging/pull/148). + +# 1.11.5 + +* Fix [#144](https://github.com/oshai/kotlin-logging/pull/144) - pom.xml has no dependencies anymore. +* Fix message formatted twice [issue #132](https://github.com/oshai/kotlin-logging/issues/132) and [PR #134](https://github.com/oshai/kotlin-logging/pull/134). +* Add automation for snapshot and release builds [#135](https://github.com/oshai/kotlin-logging/issues/135). +* Tried to upgrade to Kotlin 1.4.0, but reveted [#130](https://github.com/oshai/kotlin-logging/issues/130). + +# Versions 1.9.x,1.10.x,1.11.0-1.11.4 are obselete + +* Had deployment issues. + +# 1.8.3 + +* Add Linux X64 Support [#119](https://github.com/oshai/kotlin-logging/pull/119). + +# Versions 1.8.0.x are obselete + +* Used for testing of [#119](https://github.com/oshai/kotlin-logging/pull/119). + +# 1.7.10 + +* Remove extra space from log message in entry - [#114](https://github.com/oshai/kotlin-logging/issues/114). + +# 1.7.9 + +* update Kotlin to 1.3.70. + +# 1.7.8 + +* use dokka for kotlin javadocs - [#82](https://github.com/oshai/kotlin-logging/issues/82) +* upgrade gradle wrapper - [#100](https://github.com/oshai/kotlin-logging/issues/100) + +# 1.7.7 + +* upgrade versions - [#97](https://github.com/oshai/kotlin-logging/issues/97) + +# 1.7.6 + +* wrap slf4j logger with kotlin logger - [#88](https://github.com/oshai/kotlin-logging/issues/88) + +# 1.7.5 + +* Provide for nullable in entry and rename exit argument - [#89](https://github.com/oshai/kotlin-logging/issues/89) + +# 1.7.4 + +* Fixed nullability in exit signature: [#84](https://github.com/oshai/kotlin-logging/issues/84) [#86](https://github.com/oshai/kotlin-logging/issues/86) [#87](https://github.com/oshai/kotlin-logging/issues/87) + +# 1.7.2 + +* Fixed missing slf4j dependency - https://github.com/oshai/kotlin-logging/issues/83 + +# 1.7.1 + +* Convert project to new MPP format: https://github.com/oshai/kotlin-logging/issues/64 + +# 1.6.26 + +* Add support for slf4j-ext: https://github.com/oshai/kotlin-logging/pull/73 + +# 1.6.25 + +* Javascript - Extracting Message Formatter interface (more changes):https://github.com/oshai/kotlin-logging/pull/66 + +# 1.6.24 + +* Javascript - Extracting Message Formatter interface: https://github.com/oshai/kotlin-logging/pull/63 + +# 1.6.23 + +* Update kotlin to 1.3.20. + +# 1.6.22 + +* Fix log levels in JS: https://github.com/oshai/kotlin-logging/pull/57 +* Update kotlin to 1.3.10. + +# 1.6.20 + +* Compile with Kotlin 1.3.0: https://github.com/oshai/kotlin-logging/pull/55 thanks @walokra. + +# 1.6.0 + 1.6.10 +* Add Markers support for multiplatform [#48](https://github.com/oshai/kotlin-logging/pull/48) +* Improvement to version upload automation [#46](https://github.com/oshai/kotlin-logging/issues/46) + +# 1.5.9 +* Back to Kotlin 1.2.60, created 3 artifacts on maven central. + +# 1.5.8 +* Refactor - move toStringSafe() to common lib. +* This version (+1.5.7 which has no changes) are mostly deployed for multiplatform checks. + +# 1.5.6 +* Add Partial support for multiplatform [#21](https://github.com/oshai/kotlin-logging/issues/21) + * common and js implementation. +* kotlin version is now 1.2.30, when tried to upgrade an additional (unneeded) dependency in pom.xml on common module was created. + +# 1.5.4 +* Accept nullable Throwables [#38](https://github.com/oshai/kotlin-logging/issues/38) [#39](https://github.com/oshai/kotlin-logging/issues/39) + +# 1.5.3 +* Add Partial support for multiplatform [#21](https://github.com/oshai/kotlin-logging/issues/21) + * Split directories. + * Currently only jvm artifact is deployed. + +# 1.4.9 +* Add MDC Support [#31](https://github.com/oshai/kotlin-logging/issues/31) +* Upgrade to Kotlin 1.2.10. + +# 1.4.8 +* 1.4.7 was broken see issue [#30](https://github.com/oshai/kotlin-logging/issues/30) + +# 1.4.7 +* Upgrade to Kotlin 1.2.0. + +# 1.4.6 +* Fixed issue [#20](https://github.com/oshai/kotlin-logging/issues/20) - add `KLogger.underlyingLogger` that provides the Logger actual implementation. Can help in operations such as setting log level. + +# 1.4.5 +* Fixed issue [#22](https://github.com/oshai/kotlin-logging/pull/22) - Suppress exceptions from toString methods. + +# 1.4.4 +* Upgrade to Kotlin 1.1. + +# 1.4.3 +* Fixed issue [#17](https://github.com/oshai/kotlin-logging/issues/17) - bad location in some logging methods. + +# 1.4.2 +* Supported `null` values in parameters that allows it in slf4j. +* Update to kotlin 1.0.6. + +# 1.4.1 +* Added KotlinLogging object allow getting a logger in the following way: +```kotlin +private val logger = KotlinLogging.logger {} +``` +see issue [#12](https://github.com/oshai/kotlin-logging/issues/12) and PR [#13](https://github.com/oshai/kotlin-logging/issues/13) + +# 1.4 + +* Changed KLogger to be an interface +* Fix issue [#11](https://github.com/oshai/kotlin-logging/issues/11) - Location Awerness of logger + +# 1.3.3 + +* Remove dependency on kotlin reflection to make it even more lightweight. +* Update to kotlin 1.0.4. + + +# 1.3.2 + +* Published artifacts to maven-central. +* Added lazy evaluated message methods for throwables: https://github.com/oshai/kotlin-logging/pull/7. + +# 1.3 + +* Changed artifactId and jar name from kotlin.logging to kotlin-logging and changed groupId to io.github.microutils +* Moved the bintray path + +# 1.2.1 + +* Added tests for class name in logger in KLoggerNameResolverTest +* Added KLoggerNameResolver and KLoggerFactory +* Added documentation + +# 1.2 + +* Added KLogger method inline - better for Android methods count + +# 1.1.1 + +* Added documentation and sources jars to release +* Removed KLogger method inline - should not affect performance and line numbers will be better + +# 1.1 + +* Changed names of classes: + * WithLogging -> KLogging + * HasLogging -> KLoggable + * WithNamedLogging -> NamedKLogging diff --git a/ChangeLog.md b/ChangeLog.md index d6ace0c4..733d2ed9 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,265 +1,85 @@ -# See latest versions changelog on github [releases page](https://github.com/MicroUtils/kotlin-logging/releases) -# 2.1.20 +# `kotlin-logging` versions -* Same as `2.1.17`. +This page is the TL;DR version of the changes in major versions. -# 2.1.17 +For the full changelog see github [releases page](https://github.com/oshai/kotlin-logging/releases). +The previous changelog is available [here](https://github.com/oshai/kotlin-logging/ChangeLog-old.md). -* Upgrade log4j to 2.16.0 [#211](https://github.com/MicroUtils/kotlin-logging/pull/211) [#207](https://github.com/MicroUtils/kotlin-logging/pull/207). -* Upgrade dokka to 1.6 [#209](https://github.com/MicroUtils/kotlin-logging/pull/209). -* Fix detekt warnings [#203](https://github.com/MicroUtils/kotlin-logging/pull/203). -* Upgrade to junit 5 [#204](https://github.com/MicroUtils/kotlin-logging/pull/204). +List of versions are available also in [mvnrepository](https://mvnrepository.com/artifact/io.github.oshai/kotlin-logging) +and [maven central](https://repo1.maven.org/maven2/io/github/oshai/kotlin-logging/). -# 2.1.15 +# Overview -* Add support for mingw (windows) and osx. +The latest kotlin-logging version is 5 (now in beta). +It is the recommended version for new users and upgrades, as previous versions will require manual upgrade. -# 2.1.14 +Version 4.x is **not recommended** to use (we jumped directly from v.3 to v.5). +During the change from v.3 to v.5 the lib was "rebranded" from `MicroUtils` to `oshai`. +The github organization changed from [MicroUtils](https://github.com/MicroUtils/kotlin-logging) to [oshai](https://github.com/oshai/kotlin-logging) user +(github automatically redirects from the old to the new url). +The package name changed from `mu` to `io.github.oshai.kotlinlogging`. -* Move to github actions release. +The rationale for the change is that after v.3 (v.4, v.5) a big breaking change was introduced around multiplatform class hierarchy +and changing artifact id and package name allow to avoid compatibility issues for users of the pre v.5 versions (v.1, v.2, v.3). +In addition, what initially seems as a good idea of having an organization for the lib (micro utils), turns out as less visible as to who maintains it, and the package name was less conventional. -# 2.0.12 +Version 5 is not backward compatible with previous versions (v.3, v.2, v.1). Group id (in maven) and packages names changed. +It is possible to use both version 5 and previous versions side-by-side so some of the code from the old version +and some new. It is also possible to have libs using old version and use the new version (and vice-versa). +In that sense it's a completely new dependency. -* added the license to all jar files [#191](https://github.com/MicroUtils/kotlin-logging/pull/191. +Below is a list of all versions, some history and note-worthy changes. -# 2.0.11 +# Version 5 -* Fixed losing previous values in MDC [#187](https://github.com/MicroUtils/kotlin-logging/pull/187). - -# 2.0.10 +Released on: TBD (currently in beta). +Full change log: +[v.5](https://github.com/oshai/kotlin-logging/releases/tag/5.0.0) +and [v.4](https://github.com/oshai/kotlin-logging/releases/tag/4.0.0). -* upgrade kotlin to 1.5 [#175](https://github.com/MicroUtils/kotlin-logging/pull/175) -* unwrapCompanionClass fails to unwrap private companions when on kotlin 1.4+ [#182](https://github.com/MicroUtils/kotlin-logging/issues/182). -# 2.0.8 +Main changes are (compared to v.3): -* Publish to maven central directly [#177](https://github.com/MicroUtils/kotlin-logging/issues/177). +- Add fluent api and structured logging support (payload). +- Maven group id changed from `io.github.microutils` -> `io.github.oshai`. +- Root package change from `mu` -> `io.github.oshai.kotlinlogging`. +- Slf4j dependency is not provided anymore (users have to provide it). It means that >= 5.x can work with both slf4j 1 or 2. +- There are changes to multiplatform class hierarchy that break compatibility (the api structure around expected / actual was significantly changed).' -# 2.0.7 -* Support optional/nullable values for MDC [#172](https://github.com/MicroUtils/kotlin-logging/issues/172). +# Version 4 -# 2.0.6 +Not to be used. -* Same as `2.0.5`. +# Version 3 -# 2.0.5 +Released on: Sep 18, 2022. +Full change log: +[v.3](https://github.com/oshai/kotlin-logging/releases/tag/3.0.0) -* Upgrade Kotlin to 1.4.31. +Main Changes: +- Upgrade slf4j 1.x->2.x by @yeikel in https://github.com/oshai/kotlin-logging/pull/234 -# 2.0.4 +# Version 2 -* When an error occurs in Log message invocation then log it as an ERROR [#160](https://github.com/MicroUtils/kotlin-logging/issues/160). - -# 2.0.3 - -* Fix Bintray versions display [#152](https://github.com/MicroUtils/kotlin-logging/issues/152). - -# 2.0.2 - -* Build refactor and bintray plugin replacement [#145](https://github.com/MicroUtils/kotlin-logging/pull/145). -* Support JS-IR backend [#139](https://github.com/MicroUtils/kotlin-logging/pull/139). -* Use linux code for linux/macos/mingw targets [#131](https://github.com/MicroUtils/kotlin-logging/pull/131). -* Upgrade to Kotlin 1.4.10 [#137](https://github.com/MicroUtils/kotlin-logging/pull/137). -* Add explicit API in strict mode [#124](https://github.com/MicroUtils/kotlin-logging/issues/124). - -# 2.X changes from 1.X +Released on: Sep 20, 2020. +Full change log in the [previous changelog](https://github.com/oshai/kotlin-logging/ChangeLog-old.md). The main incompatible change is in the artifact names. In version `1.x` the jvm artifact is called `kotlin-logging` while in version `2.x` it's called `kotlin-logging-jvm` to comply with the multiplatform schema. In addition, version 2.x supports only Kotlin >= 1.4. Therefore, for jvm library owners it is still recommended to use 1.x, as for the rest of the use cases 2.x is recommended. +# Version 1 -# 1.12.5 - -* Fix Kotlin-logging version 1.12.0 is missing .module file in Maven artifact [#163](https://github.com/MicroUtils/kotlin-logging/pull/163). - -# Versions 1.12.1 - 1.12.4 are obselete - -* Break versions due to kotlin upgrade, see [#170](https://github.com/MicroUtils/kotlin-logging/issues/170). - -# 1.12.0 - -* Upgrade to Kotlin 1.4.10 [#148](https://github.com/MicroUtils/kotlin-logging/pull/148). - -# 1.11.5 - -* Fix [#144](https://github.com/MicroUtils/kotlin-logging/pull/144) - pom.xml has no dependencies anymore. -* Fix message formatted twice [issue #132](https://github.com/MicroUtils/kotlin-logging/issues/132) and [PR #134](https://github.com/MicroUtils/kotlin-logging/pull/134). -* Add automation for snapshot and release builds [#135](https://github.com/MicroUtils/kotlin-logging/issues/135). -* Tried to upgrade to Kotlin 1.4.0, but reveted [#130](https://github.com/MicroUtils/kotlin-logging/issues/130). - -# Versions 1.9.x,1.10.x,1.11.0-1.11.4 are obselete - -* Had deployment issues. - -# 1.8.3 - -* Add Linux X64 Support [#119](https://github.com/MicroUtils/kotlin-logging/pull/119). - -# Versions 1.8.0.x are obselete - -* Used for testing of [#119](https://github.com/MicroUtils/kotlin-logging/pull/119). - -# 1.7.10 - -* Remove extra space from log message in entry - [#114](https://github.com/MicroUtils/kotlin-logging/issues/114). - -# 1.7.9 - -* update Kotlin to 1.3.70. - -# 1.7.8 - -* use dokka for kotlin javadocs - [#82](https://github.com/MicroUtils/kotlin-logging/issues/82) -* upgrade gradle wrapper - [#100](https://github.com/MicroUtils/kotlin-logging/issues/100) - -# 1.7.7 - -* upgrade versions - [#97](https://github.com/MicroUtils/kotlin-logging/issues/97) - -# 1.7.6 - -* wrap slf4j logger with kotlin logger - [#88](https://github.com/MicroUtils/kotlin-logging/issues/88) - -# 1.7.5 - -* Provide for nullable in entry and rename exit argument - [#89](https://github.com/MicroUtils/kotlin-logging/issues/89) - -# 1.7.4 - -* Fixed nullability in exit signature: [#84](https://github.com/MicroUtils/kotlin-logging/issues/84) [#86](https://github.com/MicroUtils/kotlin-logging/issues/86) [#87](https://github.com/MicroUtils/kotlin-logging/issues/87) - -# 1.7.2 - -* Fixed missing slf4j dependency - https://github.com/MicroUtils/kotlin-logging/issues/83 - -# 1.7.1 - -* Convert project to new MPP format: https://github.com/MicroUtils/kotlin-logging/issues/64 - -# 1.6.26 - -* Add support for slf4j-ext: https://github.com/MicroUtils/kotlin-logging/pull/73 - -# 1.6.25 - -* Javascript - Extracting Message Formatter interface (more changes):https://github.com/MicroUtils/kotlin-logging/pull/66 - -# 1.6.24 - -* Javascript - Extracting Message Formatter interface: https://github.com/MicroUtils/kotlin-logging/pull/63 - -# 1.6.23 - -* Update kotlin to 1.3.20. - -# 1.6.22 - -* Fix log levels in JS: https://github.com/MicroUtils/kotlin-logging/pull/57 -* Update kotlin to 1.3.10. - -# 1.6.20 - -* Compile with Kotlin 1.3.0: https://github.com/MicroUtils/kotlin-logging/pull/55 thanks @walokra. - -# 1.6.0 + 1.6.10 -* Add Markers support for multiplatform [#48](https://github.com/MicroUtils/kotlin-logging/pull/48) -* Improvement to version upload automation [#46](https://github.com/MicroUtils/kotlin-logging/issues/46) - -# 1.5.9 -* Back to Kotlin 1.2.60, created 3 artifacts on maven central. - -# 1.5.8 -* Refactor - move toStringSafe() to common lib. -* This version (+1.5.7 which has no changes) are mostly deployed for multiplatform checks. - -# 1.5.6 -* Add Partial support for multiplatform [#21](https://github.com/MicroUtils/kotlin-logging/issues/21) - * common and js implementation. -* kotlin version is now 1.2.30, when tried to upgrade an additional (unneeded) dependency in pom.xml on common module was created. - -# 1.5.4 -* Accept nullable Throwables [#38](https://github.com/MicroUtils/kotlin-logging/issues/38) [#39](https://github.com/MicroUtils/kotlin-logging/issues/39) - -# 1.5.3 -* Add Partial support for multiplatform [#21](https://github.com/MicroUtils/kotlin-logging/issues/21) - * Split directories. - * Currently only jvm artifact is deployed. - -# 1.4.9 -* Add MDC Support [#31](https://github.com/MicroUtils/kotlin-logging/issues/31) -* Upgrade to Kotlin 1.2.10. - -# 1.4.8 -* 1.4.7 was broken see issue [#30](https://github.com/MicroUtils/kotlin-logging/issues/30) - -# 1.4.7 -* Upgrade to Kotlin 1.2.0. - -# 1.4.6 -* Fixed issue [#20](https://github.com/MicroUtils/kotlin-logging/issues/20) - add `KLogger.underlyingLogger` that provides the Logger actual implementation. Can help in operations such as setting log level. - -# 1.4.5 -* Fixed issue [#22](https://github.com/MicroUtils/kotlin-logging/pull/22) - Suppress exceptions from toString methods. - -# 1.4.4 -* Upgrade to Kotlin 1.1. - -# 1.4.3 -* Fixed issue [#17](https://github.com/MicroUtils/kotlin-logging/issues/17) - bad location in some logging methods. - -# 1.4.2 -* Supported `null` values in parameters that allows it in slf4j. -* Update to kotlin 1.0.6. - -# 1.4.1 -* Added KotlinLogging object allow getting a logger in the following way: -```kotlin -private val logger = KotlinLogging.logger {} -``` -see issue [#12](https://github.com/MicroUtils/kotlin-logging/issues/12) and PR [#13](https://github.com/MicroUtils/kotlin-logging/issues/13) - -# 1.4 - -* Changed KLogger to be an interface -* Fix issue [#11](https://github.com/MicroUtils/kotlin-logging/issues/11) - Location Awerness of logger - -# 1.3.3 - -* Remove dependency on kotlin reflection to make it even more lightweight. -* Update to kotlin 1.0.4. - - -# 1.3.2 - -* Published artifacts to maven-central. -* Added lazy evaluated message methods for throwables: https://github.com/MicroUtils/kotlin-logging/pull/7. - -# 1.3 - -* Changed artifactId and jar name from kotlin.logging to kotlin-logging and changed groupId to io.github.microutils -* Moved the bintray path - -# 1.2.1 - -* Added tests for class name in logger in KLoggerNameResolverTest -* Added KLoggerNameResolver and KLoggerFactory -* Added documentation - -# 1.2 - -* Added KLogger method inline - better for Android methods count +First GA release. +Released on: Jul 13, 2016. +Full change log in the [previous changelog](https://github.com/oshai/kotlin-logging/ChangeLog-old.md). -# 1.1.1 -* Added documentation and sources jars to release -* Removed KLogger method inline - should not affect performance and line numbers will be better +# Version 0.1 -# 1.1 +Initial Release. +Released on: Jul 5, 2016. +Full change log in the [previous changelog](https://github.com/oshai/kotlin-logging/ChangeLog-old.md). -* Changed names of classes: - * WithLogging -> KLogging - * HasLogging -> KLoggable - * WithNamedLogging -> NamedKLogging diff --git a/README.md b/README.md index 137ae6b7..598f5907 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,9 @@ logger.atWarn { ```Kotlin import io.github.oshai.kotlinlogging.KotlinLogging + private val logger = KotlinLogging.logger {} + class FooWithLogging { val message = "world" fun bar() { @@ -61,10 +63,10 @@ class FooWithLogging { An `Android` example project with kotlin-logging can be found in [kotlin-logging-example-android](https://github.com/oshai/kotlin-logging-example-android). -## Version >= 4 vs. previous versions +## Version 5 vs. previous versions -Version >= 4 is not backward compatible with previous versions. Group id (in maven) and packages names changed. -It is possible to use both version 4 and previous versions side-by-side so some of the code from the old version +Version 5 is not backward compatible with previous versions (v.3, v.2, v.1). Group id (in maven) and packages names changed. +It is possible to use both version 5 and previous versions side-by-side so some of the code from the old version and some new. It is also possible to have libs using old version and use the new version (and vice-versa). In that sense it's a completely new dependency. @@ -74,7 +76,8 @@ Main changes are: - Slf4j dependency is not provided anymore (users have to provide it). It means that >= 4.x can work with both slf4j 1 or 2. - There are changes to multiplatform class hierarchy that might break compatibility. -More details in issue [#264](https://github.com/oshai/kotlin-logging/issues/264). +More details in issue [#264](https://github.com/oshai/kotlin-logging/issues/264), +and in the [change log](https://github.com/oshai/kotlin-logging/ChangeLog.md) ## Download From 73808f75accc91a8f0c0104f930c48c50f983cf4 Mon Sep 17 00:00:00 2001 From: oshai Date: Thu, 13 Jul 2023 10:41:47 +0300 Subject: [PATCH 04/26] update docs for v.5 --- README.md | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 598f5907..0148bd79 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,6 @@ class FooWithLogging { } ``` -An `Android` example project with kotlin-logging can be found in [kotlin-logging-example-android](https://github.com/oshai/kotlin-logging-example-android). ## Version 5 vs. previous versions @@ -91,7 +90,7 @@ In short, if you just want to log statements to stdout, it's possible to add the io.github.oshai kotlin-logging-jvm - 5.0.0-beta-01 + 5.0.0-beta-04 ``` Or @@ -106,7 +105,7 @@ See the full example in [kotlin-logging-example-maven](https://github.com/oshai/ ### Gradle ```Groovy -implementation 'io.github.oshai:kotlin-logging-jvm:5.0.0-beta-01' +implementation 'io.github.oshai:kotlin-logging-jvm:5.0.0-beta-04' ``` Or ```Groovy @@ -117,7 +116,7 @@ Alternatively, download the JAR from [github](https://github.com/oshai/kotlin-lo ### Multiplatform -An experimental common & JS & linux-x64 support is available. +An experimental multiplatform support is available. More information is available on the [wiki](https://github.com/oshai/kotlin-logging/wiki/Multiplatform-support) and issues [#21](https://github.com/oshai/kotlin-logging/issues/21) [#45](https://github.com/oshai/kotlin-logging/issues/45). ## Overview @@ -141,10 +140,10 @@ And many more... (add your name above) ## FAQ - Why not use plain slf4j? kotlin-logging has better native Kotlin support. It adds more functionality and enables less boilerplate code. -- Is all slf4j implementation supported (Markers, params, etc')? Yes, kotlin-logging inherits Logger and all methods are supported. +- Is all slf4j implementation supported (Markers, params, etc')? Yes. - Is location logging possible? Yes, location awareness was added in kotlin-logging 1.4. - When I do `logger.debug`, my IntelliJ IDEA run console doesn't show any output. Do you know how I could set the console logger to debug or trace levels? Is this an IDE setting, or can it be set in the call to KLogging()? Setting log level is done per implementation. kotlin-logging and slf4j are just facades for the underlying logging lib (log4j, logback etc') more details [here](http://stackoverflow.com/questions/43146977/how-to-configure-kotlin-logging-logger). -- Can I access the actual logger? Yes, via `KLogger.underlyingLogger` property. +- Can I access the actual logger? In platforms available yes, via `DelegatingKLogger.underlyingLogger` property. ## Usage From 5c5562936e4a73c469a07546d61d017eead342a8 Mon Sep 17 00:00:00 2001 From: oshai Date: Thu, 13 Jul 2023 10:46:54 +0300 Subject: [PATCH 05/26] update broken links --- ChangeLog.md | 6 +++--- README.md | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 733d2ed9..66ce1f1c 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -64,7 +64,7 @@ Main Changes: # Version 2 Released on: Sep 20, 2020. -Full change log in the [previous changelog](https://github.com/oshai/kotlin-logging/ChangeLog-old.md). +Full change log in the [previous changelog](https://github.com/oshai/kotlin-logging/blob/master/ChangeLog-old.md). The main incompatible change is in the artifact names. In version `1.x` the jvm artifact is called `kotlin-logging` while in version `2.x` it's called `kotlin-logging-jvm` to comply with the multiplatform schema. In addition, version 2.x supports only Kotlin >= 1.4. @@ -74,12 +74,12 @@ Therefore, for jvm library owners it is still recommended to use 1.x, as for the First GA release. Released on: Jul 13, 2016. -Full change log in the [previous changelog](https://github.com/oshai/kotlin-logging/ChangeLog-old.md). +Full change log in the [previous changelog](https://github.com/oshai/kotlin-logging/blob/master/ChangeLog-old.md). # Version 0.1 Initial Release. Released on: Jul 5, 2016. -Full change log in the [previous changelog](https://github.com/oshai/kotlin-logging/ChangeLog-old.md). +Full change log in the [previous changelog](https://github.com/oshai/kotlin-logging/blob/master/ChangeLog-old.md). diff --git a/README.md b/README.md index 0148bd79..a56d3f55 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ Main changes are: - There are changes to multiplatform class hierarchy that might break compatibility. More details in issue [#264](https://github.com/oshai/kotlin-logging/issues/264), -and in the [change log](https://github.com/oshai/kotlin-logging/ChangeLog.md) +and in the [change log](https://github.com/oshai/kotlin-logging/blob/master/ChangeLog.md) ## Download From 15b073812e1ccfa6d0310a1fbb058487c40dc73a Mon Sep 17 00:00:00 2001 From: Ohad Shai Date: Sat, 15 Jul 2023 08:28:53 +0300 Subject: [PATCH 06/26] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a56d3f55..c473cc23 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ In that sense it's a completely new dependency. Main changes are: - Maven group id changed from `io.github.microutils` -> `io.github.oshai`. - Root package change from `mu` -> `io.github.oshai.kotlinlogging`. -- Slf4j dependency is not provided anymore (users have to provide it). It means that >= 4.x can work with both slf4j 1 or 2. +- Slf4j dependency is not provided anymore (users have to provide it). It means that >= 5.x can work with both slf4j 1 or 2. - There are changes to multiplatform class hierarchy that might break compatibility. More details in issue [#264](https://github.com/oshai/kotlin-logging/issues/264), From b40188ae8e2d9d29b0b283c1ca5e488328a7dcaa Mon Sep 17 00:00:00 2001 From: Ohad Shai Date: Sat, 15 Jul 2023 08:31:49 +0300 Subject: [PATCH 07/26] Update ChangeLog.md --- ChangeLog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ChangeLog.md b/ChangeLog.md index 66ce1f1c..14134e75 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -50,7 +50,7 @@ Main changes are (compared to v.3): # Version 4 -Not to be used. +Not to be used. Immediately after releasing the changes it was decided some more breaking changes are required so skipping this version. # Version 3 From 1147528d09fdeb13aa1eb3a54b543ee0700ca994 Mon Sep 17 00:00:00 2001 From: Ohad Shai Date: Sat, 15 Jul 2023 08:34:04 +0300 Subject: [PATCH 08/26] Update ChangeLog.md --- ChangeLog.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 14134e75..4d984e68 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -68,8 +68,6 @@ Full change log in the [previous changelog](https://github.com/oshai/kotlin-logg The main incompatible change is in the artifact names. In version `1.x` the jvm artifact is called `kotlin-logging` while in version `2.x` it's called `kotlin-logging-jvm` to comply with the multiplatform schema. In addition, version 2.x supports only Kotlin >= 1.4. -Therefore, for jvm library owners it is still recommended to use 1.x, as for the rest of the use cases 2.x is recommended. - # Version 1 First GA release. From 37e42a696c20e2694acac5deec2f5a6e3844538d Mon Sep 17 00:00:00 2001 From: oshai Date: Wed, 19 Jul 2023 08:58:34 +0300 Subject: [PATCH 09/26] bump version to 5.0.0 --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index 6f6157ac..af8248be 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -17,7 +17,7 @@ plugins { apply("versions.gradle.kts") group = "io.github.oshai" -version = "5.0.0-beta-05" +version = "5.0.0" repositories { gradlePluginPortal() From ed3946a28dd0d0089a57c4204ad4522f8047d7c9 Mon Sep 17 00:00:00 2001 From: oshai Date: Wed, 19 Jul 2023 09:00:36 +0300 Subject: [PATCH 10/26] bump version to 5.0.1 --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index af8248be..f9030e3f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -17,7 +17,7 @@ plugins { apply("versions.gradle.kts") group = "io.github.oshai" -version = "5.0.0" +version = "5.0.1" repositories { gradlePluginPortal() From 587aa4781b8c2abf636aaee24e0fbc915aa4f30b Mon Sep 17 00:00:00 2001 From: Ohad Shai Date: Fri, 21 Jul 2023 15:50:12 +0300 Subject: [PATCH 11/26] Update ChangeLog.md --- ChangeLog.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 4d984e68..58b11e15 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -11,7 +11,7 @@ and [maven central](https://repo1.maven.org/maven2/io/github/oshai/kotlin-loggin # Overview -The latest kotlin-logging version is 5 (now in beta). +The latest kotlin-logging version is 5. It is the recommended version for new users and upgrades, as previous versions will require manual upgrade. Version 4.x is **not recommended** to use (we jumped directly from v.3 to v.5). @@ -33,7 +33,7 @@ Below is a list of all versions, some history and note-worthy changes. # Version 5 -Released on: TBD (currently in beta). +Released on: July 19, 2023. Full change log: [v.5](https://github.com/oshai/kotlin-logging/releases/tag/5.0.0) and [v.4](https://github.com/oshai/kotlin-logging/releases/tag/4.0.0). From bbd570826cdf01766f4375906970e868526477c1 Mon Sep 17 00:00:00 2001 From: Ohad Shai Date: Fri, 21 Jul 2023 22:17:12 +0300 Subject: [PATCH 12/26] Update README.md --- README.md | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index c473cc23..7ee49390 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,7 @@ and in the [change log](https://github.com/oshai/kotlin-logging/blob/master/Chan ## Download **Important note:** kotlin-logging depends on slf4j-api (in the JVM artifact). In runtime, it is also required to depend on a logging implementation. More details in [how-to-configure-slf4j](http://saltnlight5.blogspot.co.il/2013/08/how-to-configure-slf4j-with-different.html). And an excellent detailed explanation in [a-guide-to-logging-in-java](https://www.marcobehler.com/guides/a-guide-to-logging-in-java). -In version 4 users should also provide slf4j-api dependency. +In version 5 users should also provide slf4j-api dependency. In short, if you just want to log statements to stdout, it's possible to add the following dependency: `org.slf4j:slf4j-simple:2.0.3`. @@ -90,28 +90,18 @@ In short, if you just want to log statements to stdout, it's possible to add the io.github.oshai kotlin-logging-jvm - 5.0.0-beta-04 - -``` -Or -```xml - - io.github.microutils - kotlin-logging-jvm - 3.0.5 + 5.0.0 ``` + See the full example in [kotlin-logging-example-maven](https://github.com/oshai/kotlin-logging-example-maven). ### Gradle ```Groovy -implementation 'io.github.oshai:kotlin-logging-jvm:5.0.0-beta-04' -``` -Or -```Groovy -implementation 'io.github.microutils:kotlin-logging-jvm:3.0.5' +implementation 'io.github.oshai:kotlin-logging-jvm:5.0.0' ``` + Alternatively, download the JAR from [github](https://github.com/oshai/kotlin-logging/releases/latest) or [maven-central](https://repo1.maven.org/maven2/io/github/oshai/). ### Multiplatform From 9c38c49195dfe9672ff6690b29f13c13e919fd01 Mon Sep 17 00:00:00 2001 From: Ohad Shai Date: Mon, 24 Jul 2023 09:17:33 +0300 Subject: [PATCH 13/26] fix deprecated "replaceWith" directive (#340) --- .../io/github/oshai/kotlinlogging/KLogger.kt | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/commonMain/kotlin/io/github/oshai/kotlinlogging/KLogger.kt b/src/commonMain/kotlin/io/github/oshai/kotlinlogging/KLogger.kt index d8009c61..2bce707f 100644 --- a/src/commonMain/kotlin/io/github/oshai/kotlinlogging/KLogger.kt +++ b/src/commonMain/kotlin/io/github/oshai/kotlinlogging/KLogger.kt @@ -253,27 +253,27 @@ public interface KLogger { @Deprecated("use error instead", ReplaceWith("error(t, marker, msg)")) public fun error(marker: Marker?, t: Throwable?, msg: () -> Any?): Unit = error(t, marker, msg) - @Deprecated("Use isTraceEnabled instead", ReplaceWith("isTraceEnabled")) + @Deprecated("Use isTraceEnabled() instead", ReplaceWith("isTraceEnabled()")) public val isTraceEnabled: Boolean get() = isTraceEnabled() - @Deprecated("Use isDebugEnabled instead", ReplaceWith("isDebugEnabled")) + @Deprecated("Use isDebugEnabled() instead", ReplaceWith("isDebugEnabled()")) public val isDebugEnabled: Boolean get() = isDebugEnabled() - @Deprecated("Use isInfoEnabled instead", ReplaceWith("isInfoEnabled")) + @Deprecated("Use isInfoEnabled() instead", ReplaceWith("isInfoEnabled()")) public val isInfoEnabled: Boolean get() = isInfoEnabled() - @Deprecated("Use isWarnEnabled instead", ReplaceWith("isWarnEnabled")) + @Deprecated("Use isWarnEnabled() instead", ReplaceWith("isWarnEnabled()")) public val isWarnEnabled: Boolean get() = isWarnEnabled() - @Deprecated("Use isErrorEnabled instead", ReplaceWith("isErrorEnabled")) + @Deprecated("Use isErrorEnabled() instead", ReplaceWith("isErrorEnabled()")) public val isErrorEnabled: Boolean get() = isErrorEnabled() - @Deprecated("Use isLoggingOff instead", ReplaceWith("isLoggingOff")) + @Deprecated("Use isLoggingOff() instead", ReplaceWith("isLoggingOff()")) public val isLoggingOff: Boolean get() = isLoggingOff() @@ -398,7 +398,7 @@ public interface KLogger { * * @param msg the message string to be logged */ - @Deprecated("Use debug {} instead", replaceWith = ReplaceWith("debug { \"\$msg\"}")) + @Deprecated("Use debug {} instead", replaceWith = ReplaceWith("debug { msg }")) public fun debug(msg: String?): Unit = debug { msg } /** @@ -514,7 +514,8 @@ public interface KLogger { * * @param msg the message string to be logged */ - @Deprecated("Use info {} instead") public fun info(msg: String?): Unit = info { msg } + @Deprecated("Use info {} instead", ReplaceWith("info { msg }")) + public fun info(msg: String?): Unit = info { msg } /** * Log a message at the INFO level according to the specified msg and argument. @@ -628,7 +629,8 @@ public interface KLogger { * * @param msg the message string to be logged */ - @Deprecated("Use warn {} instead") public fun warn(msg: String?): Unit = warn { msg } + @Deprecated("Use warn {} instead", ReplaceWith("warn { msg }")) + public fun warn(msg: String?): Unit = warn { msg } /** * Log a message at the WARN level according to the specified msg and argument. @@ -742,7 +744,7 @@ public interface KLogger { * * @param msg the message string to be logged */ - @Deprecated("Use error {} instead", replaceWith = ReplaceWith("error { \"\$msg\"}")) + @Deprecated("Use error {} instead", replaceWith = ReplaceWith("error { msg }")) public fun error(msg: String?): Unit = error { msg } /** From 8941ed840d3749bcbd3135aac6a69f3e6ac69708 Mon Sep 17 00:00:00 2001 From: oshai Date: Mon, 24 Jul 2023 09:19:05 +0300 Subject: [PATCH 14/26] bump version to 5.0.2 --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index f9030e3f..1483d32e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -17,7 +17,7 @@ plugins { apply("versions.gradle.kts") group = "io.github.oshai" -version = "5.0.1" +version = "5.0.2" repositories { gradlePluginPortal() From 7109895638d16651714e6a9ff70d978c1b9ad188 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 24 Jul 2023 05:41:40 +0000 Subject: [PATCH 15/26] Bump com.diffplug.spotless from 6.19.0 to 6.20.0 Bumps com.diffplug.spotless from 6.19.0 to 6.20.0. --- updated-dependencies: - dependency-name: com.diffplug.spotless dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index 1483d32e..58008297 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -10,7 +10,7 @@ plugins { signing id("io.gitlab.arturbosch.detekt") version "1.18.0" id("com.android.library") version "7.4.2" - id("com.diffplug.spotless") version "6.19.0" + id("com.diffplug.spotless") version "6.20.0" } From 356a8c3ff292fab54fb3cd4d9bb7a9ba7bc48451 Mon Sep 17 00:00:00 2001 From: Ohad Shai Date: Tue, 1 Aug 2023 00:47:54 +0300 Subject: [PATCH 16/26] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7ee49390..49b06e63 100644 --- a/README.md +++ b/README.md @@ -90,7 +90,7 @@ In short, if you just want to log statements to stdout, it's possible to add the io.github.oshai kotlin-logging-jvm - 5.0.0 + 5.0.1 ``` @@ -98,7 +98,7 @@ See the full example in [kotlin-logging-example-maven](https://github.com/oshai/ ### Gradle ```Groovy -implementation 'io.github.oshai:kotlin-logging-jvm:5.0.0' +implementation 'io.github.oshai:kotlin-logging-jvm:5.0.1' ``` From 767a1ae2aeba629e1e51e44af110bfd2f7b60552 Mon Sep 17 00:00:00 2001 From: Ohad Shai Date: Tue, 1 Aug 2023 09:46:10 +0300 Subject: [PATCH 17/26] move DelegatingKLogger to separate file (#344) --- .../io/github/oshai/kotlinlogging/DelegatingKLogger.kt | 6 ++++++ .../kotlin/io/github/oshai/kotlinlogging/KLogger.kt | 5 ----- 2 files changed, 6 insertions(+), 5 deletions(-) create mode 100644 src/commonMain/kotlin/io/github/oshai/kotlinlogging/DelegatingKLogger.kt diff --git a/src/commonMain/kotlin/io/github/oshai/kotlinlogging/DelegatingKLogger.kt b/src/commonMain/kotlin/io/github/oshai/kotlinlogging/DelegatingKLogger.kt new file mode 100644 index 00000000..f468588d --- /dev/null +++ b/src/commonMain/kotlin/io/github/oshai/kotlinlogging/DelegatingKLogger.kt @@ -0,0 +1,6 @@ +package io.github.oshai.kotlinlogging + +public interface DelegatingKLogger { + /** The actual logger executing logging */ + public val underlyingLogger: T +} diff --git a/src/commonMain/kotlin/io/github/oshai/kotlinlogging/KLogger.kt b/src/commonMain/kotlin/io/github/oshai/kotlinlogging/KLogger.kt index 2bce707f..109fba4e 100644 --- a/src/commonMain/kotlin/io/github/oshai/kotlinlogging/KLogger.kt +++ b/src/commonMain/kotlin/io/github/oshai/kotlinlogging/KLogger.kt @@ -852,8 +852,3 @@ public interface KLogger { @Deprecated("Use error instead", ReplaceWith("error(t, marker, msg)")) public fun error(marker: Marker?, msg: String?, t: Throwable?): Unit = error(t, marker) { msg } } - -public interface DelegatingKLogger { - /** The actual logger executing logging */ - public val underlyingLogger: T -} From c6eaceb41042a9080af90b7aa0c2ffb0cf890a0b Mon Sep 17 00:00:00 2001 From: oshai Date: Tue, 1 Aug 2023 09:53:17 +0300 Subject: [PATCH 18/26] bump version to 5.0.3 --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index 58008297..cc828dd4 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -17,7 +17,7 @@ plugins { apply("versions.gradle.kts") group = "io.github.oshai" -version = "5.0.2" +version = "5.0.3" repositories { gradlePluginPortal() From b1e8e8bae9afc1f0186bc644c98a8672741b6d8e Mon Sep 17 00:00:00 2001 From: Ohad Shai Date: Wed, 9 Aug 2023 09:19:34 +0300 Subject: [PATCH 19/26] change darwin impl to delegate to os_log_t (#348) based on previous impl and https://blog.shipbook.io/ios-logs looks like a better approach will be to just delegate logs to the os logger. * change subsystem and category resolution based on #227 * add constant logger * add constant constantOsDefaultLogger --- build.gradle.kts | 2 +- .../oshai/kotlinlogging/DarwinKLogger.kt | 42 ++++++++++++++++ .../KotlinLoggingConfiguration.kt | 7 ++- .../oshai/kotlinlogging/OSLogAppender.kt | 48 ------------------- .../kotlinlogging/OSLogSubsystemAppender.kt | 28 ----------- .../internal/ErrorMessageProducer.kt | 3 ++ .../kotlinlogging/internal/KLoggerFactory.kt | 42 ++++++++++++++++ .../internal/KLoggerNameResolver.kt | 6 +++ 8 files changed, 100 insertions(+), 78 deletions(-) create mode 100644 src/darwinMain/kotlin/io/github/oshai/kotlinlogging/DarwinKLogger.kt delete mode 100644 src/darwinMain/kotlin/io/github/oshai/kotlinlogging/OSLogAppender.kt delete mode 100644 src/darwinMain/kotlin/io/github/oshai/kotlinlogging/OSLogSubsystemAppender.kt create mode 100644 src/darwinMain/kotlin/io/github/oshai/kotlinlogging/internal/ErrorMessageProducer.kt create mode 100644 src/darwinMain/kotlin/io/github/oshai/kotlinlogging/internal/KLoggerFactory.kt create mode 100644 src/darwinMain/kotlin/io/github/oshai/kotlinlogging/internal/KLoggerNameResolver.kt diff --git a/build.gradle.kts b/build.gradle.kts index cc828dd4..8a628eb2 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -166,7 +166,7 @@ kotlin { dependsOn(nativeMain) } val darwinMain by creating { - dependsOn(nativeMain) + dependsOn(commonMain) } linuxTargets.forEach { getByName("${it.targetName}Main") { diff --git a/src/darwinMain/kotlin/io/github/oshai/kotlinlogging/DarwinKLogger.kt b/src/darwinMain/kotlin/io/github/oshai/kotlinlogging/DarwinKLogger.kt new file mode 100644 index 00000000..59e89aaa --- /dev/null +++ b/src/darwinMain/kotlin/io/github/oshai/kotlinlogging/DarwinKLogger.kt @@ -0,0 +1,42 @@ +package io.github.oshai.kotlinlogging + +import kotlinx.cinterop.ptr +import platform.darwin.OS_LOG_TYPE_DEBUG +import platform.darwin.OS_LOG_TYPE_DEFAULT +import platform.darwin.OS_LOG_TYPE_ERROR +import platform.darwin.OS_LOG_TYPE_INFO +import platform.darwin.__dso_handle +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 + +public class DarwinKLogger(override val name: String, override val underlyingLogger: os_log_t) : + KLogger, DelegatingKLogger { + + override fun at(level: Level, marker: Marker?, block: KLoggingEventBuilder.() -> Unit) { + if (isLoggingEnabledFor(level, marker)) { + KLoggingEventBuilder().apply(block).run { + _os_log_internal(__dso_handle.ptr, underlyingLogger, level.toDarwinLevel(), message) + } + } + } + + private fun Level.toDarwinLevel(): os_log_type_t { + return when (this) { + Level.TRACE -> OS_LOG_TYPE_DEBUG + Level.DEBUG -> OS_LOG_TYPE_DEBUG + Level.INFO -> OS_LOG_TYPE_INFO + Level.WARN -> OS_LOG_TYPE_DEFAULT + Level.ERROR -> OS_LOG_TYPE_ERROR + Level.OFF -> throw Exception("off level cannot be mapped to darwin level") + } + } + + override fun isLoggingEnabledFor(level: Level, marker: Marker?): Boolean { + return when (level) { + Level.OFF -> false + else -> os_log_type_enabled(underlyingLogger, level.toDarwinLevel()) + } + } +} diff --git a/src/darwinMain/kotlin/io/github/oshai/kotlinlogging/KotlinLoggingConfiguration.kt b/src/darwinMain/kotlin/io/github/oshai/kotlinlogging/KotlinLoggingConfiguration.kt index 3cb53b66..d9b2c927 100644 --- a/src/darwinMain/kotlin/io/github/oshai/kotlinlogging/KotlinLoggingConfiguration.kt +++ b/src/darwinMain/kotlin/io/github/oshai/kotlinlogging/KotlinLoggingConfiguration.kt @@ -1,3 +1,8 @@ package io.github.oshai.kotlinlogging -public actual val DefaultAppender: Appender = OSLogAppender() +import kotlin.native.concurrent.AtomicReference + +public object KotlinLoggingConfiguration { + public var subsystem: AtomicReference = AtomicReference(null) + public var category: AtomicReference = AtomicReference(null) +} diff --git a/src/darwinMain/kotlin/io/github/oshai/kotlinlogging/OSLogAppender.kt b/src/darwinMain/kotlin/io/github/oshai/kotlinlogging/OSLogAppender.kt deleted file mode 100644 index 59602be9..00000000 --- a/src/darwinMain/kotlin/io/github/oshai/kotlinlogging/OSLogAppender.kt +++ /dev/null @@ -1,48 +0,0 @@ -package io.github.oshai.kotlinlogging - -import kotlinx.cinterop.ptr -import platform.darwin.OS_LOG_DEFAULT -import platform.darwin.OS_LOG_TYPE_DEBUG -import platform.darwin.OS_LOG_TYPE_DEFAULT -import platform.darwin.OS_LOG_TYPE_ERROR -import platform.darwin.OS_LOG_TYPE_INFO -import platform.darwin.__dso_handle -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 - -public open class OSLogAppender : Appender { - override val includePrefix: Boolean = true - - 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) - } - } - - 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 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 error(loggerName: String, message: String) { - log(OS_LOG_TYPE_ERROR, loggerName, message) - } -} diff --git a/src/darwinMain/kotlin/io/github/oshai/kotlinlogging/OSLogSubsystemAppender.kt b/src/darwinMain/kotlin/io/github/oshai/kotlinlogging/OSLogSubsystemAppender.kt deleted file mode 100644 index bfa1a2d3..00000000 --- a/src/darwinMain/kotlin/io/github/oshai/kotlinlogging/OSLogSubsystemAppender.kt +++ /dev/null @@ -1,28 +0,0 @@ -package io.github.oshai.kotlinlogging - -import kotlin.native.concurrent.AtomicReference -import platform.darwin.os_log_create -import platform.darwin.os_log_t - -public class OSLogSubsystemAppender(public val subsystem: String) : OSLogAppender() { - override val includePrefix: Boolean = false - - 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 - } - - val updated = existing.toMutableMap() - logger = os_log_create(subsystem, loggerName) - updated[loggerName] = logger - } while (!logs.compareAndSet(existing, updated)) - - return logger - } -} diff --git a/src/darwinMain/kotlin/io/github/oshai/kotlinlogging/internal/ErrorMessageProducer.kt b/src/darwinMain/kotlin/io/github/oshai/kotlinlogging/internal/ErrorMessageProducer.kt new file mode 100644 index 00000000..6d35a773 --- /dev/null +++ b/src/darwinMain/kotlin/io/github/oshai/kotlinlogging/internal/ErrorMessageProducer.kt @@ -0,0 +1,3 @@ +package io.github.oshai.kotlinlogging.internal + +internal actual typealias ErrorMessageProducer = DefaultErrorMessageProducer diff --git a/src/darwinMain/kotlin/io/github/oshai/kotlinlogging/internal/KLoggerFactory.kt b/src/darwinMain/kotlin/io/github/oshai/kotlinlogging/internal/KLoggerFactory.kt new file mode 100644 index 00000000..41592817 --- /dev/null +++ b/src/darwinMain/kotlin/io/github/oshai/kotlinlogging/internal/KLoggerFactory.kt @@ -0,0 +1,42 @@ +package io.github.oshai.kotlinlogging.internal + +import io.github.oshai.kotlinlogging.DarwinKLogger +import io.github.oshai.kotlinlogging.KLogger +import io.github.oshai.kotlinlogging.KotlinLoggingConfiguration +import kotlin.native.concurrent.AtomicReference +import platform.darwin.OS_LOG_DEFAULT +import platform.darwin.os_log_create + +/** factory methods to obtain a [KLogger] */ +internal actual object KLoggerFactory { + + private val constantLogger: AtomicReference = AtomicReference(null) + private val constantOsDefaultLogger: KLogger = DarwinKLogger("", OS_LOG_DEFAULT) + + /** get logger by explicit name */ + internal actual fun logger(name: String): KLogger { + val subsystemConfigured = KotlinLoggingConfiguration.subsystem.value + val categoryConfigured = KotlinLoggingConfiguration.category.value + return when { + subsystemConfigured != null && categoryConfigured != null -> { + constantLogger.value + ?: DarwinKLogger(name, os_log_create(subsystemConfigured, categoryConfigured)).also { + constantLogger.value = it + } + } + subsystemConfigured != null || categoryConfigured != null -> { + DarwinKLogger(name, os_log_create(subsystemConfigured ?: name, categoryConfigured ?: name)) + } + name.isBlank() -> constantOsDefaultLogger + name.contains(".") -> { + DarwinKLogger( + name, + os_log_create(name.substringBeforeLast("."), name.substringAfterLast(".")) + ) + } + else -> { + DarwinKLogger(name, os_log_create(name, "")) + } + } + } +} diff --git a/src/darwinMain/kotlin/io/github/oshai/kotlinlogging/internal/KLoggerNameResolver.kt b/src/darwinMain/kotlin/io/github/oshai/kotlinlogging/internal/KLoggerNameResolver.kt new file mode 100644 index 00000000..fb420756 --- /dev/null +++ b/src/darwinMain/kotlin/io/github/oshai/kotlinlogging/internal/KLoggerNameResolver.kt @@ -0,0 +1,6 @@ +package io.github.oshai.kotlinlogging.internal + +internal actual object KLoggerNameResolver { + + internal actual fun name(func: () -> Unit): String = func::class.qualifiedName ?: "" +} From a821a7861d4bfd5a0ed856948f91ebb8609137a2 Mon Sep 17 00:00:00 2001 From: oshai Date: Thu, 10 Aug 2023 09:26:37 +0300 Subject: [PATCH 20/26] bump version to 5.1.0 --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index 8a628eb2..16e42ebf 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -17,7 +17,7 @@ plugins { apply("versions.gradle.kts") group = "io.github.oshai" -version = "5.0.3" +version = "5.1.0" repositories { gradlePluginPortal() From 6a3f37c2219d83fe9cddad974a54eb5ad70f0689 Mon Sep 17 00:00:00 2001 From: Ohad Shai Date: Thu, 10 Aug 2023 09:48:42 +0300 Subject: [PATCH 21/26] consolidate platforms with non-delegating impl (#350) create directMain source set as base for all non-delegating platforms - platforms that use kotlin-logging to write the logs with native kotlin functions and not via other libs or platform constructs. This change the js/linux/etc' platforms. Some duplication was removed. And the way it is now configured changed. `KotlinLoggingConfiguration` now contains: - logLevel - formatter - appender Those interfaces changed. Logger now calls the appender that is responsible to call the formatter - unlike previously where it called the formatter and passed the message to the appender. Appender don't need to check if log is enabled, and has a single method: `fun log(loggingEvent: KLoggingEvent)` (which contains also payload). Formatter has a single method: `fun formatMessage(loggingEvent: KLoggingEvent): String` which returns a formatted message. * old upper case names in js are now deprecated and delegating to those. --- build.gradle.kts | 7 ++- .../io/github/oshai/kotlinlogging/Appender.kt | 14 ++++++ .../github/oshai/kotlinlogging/Formatter.kt | 44 +++++++++++++++++++ .../oshai/kotlinlogging/KLoggingEvent.kt | 24 ++++++++++ .../KotlinLoggingConfiguration.kt | 7 +++ .../oshai/kotlinlogging/KotlinLoggingLevel.kt | 0 .../internal/ErrorMessageProducer.kt | 0 .../kotlinlogging/internal/KLoggerDirect.kt | 28 ++++++++++++ .../kotlinlogging/internal/KLoggerFactory.kt | 2 +- .../io/github/oshai/kotlinlogging/Appender.kt | 9 ---- .../kotlinlogging/ConsoleOutputAppender.kt | 17 ++++--- .../kotlinlogging/DefaultMessageFormatter.kt | 40 ----------------- .../github/oshai/kotlinlogging/Formatter.kt | 11 ----- .../KotlinLoggingConfiguration.kt | 21 +++++++-- .../oshai/kotlinlogging/KotlinLoggingLevel.kt | 5 --- .../kotlinlogging/internal/KLoggerFactory.kt | 8 ---- .../oshai/kotlinlogging/internal/KLoggerJS.kt | 37 ---------------- .../oshai/kotlinlogging/SimpleJsTest.kt | 28 ++---------- .../io/github/oshai/kotlinlogging/Appender.kt | 11 ----- .../kotlinlogging/ConsoleOutputAppender.kt | 16 +++---- .../kotlinlogging/DefaultMessageFormatter.kt | 37 ---------------- .../github/oshai/kotlinlogging/Formatter.kt | 13 ------ .../KotlinLoggingConfiguration.kt | 10 ++--- .../internal/ErrorMessageProducer.kt | 3 -- .../kotlinlogging/internal/KLoggerNative.kt | 36 --------------- 25 files changed, 167 insertions(+), 261 deletions(-) create mode 100644 src/directMain/kotlin/io/github/oshai/kotlinlogging/Appender.kt create mode 100644 src/directMain/kotlin/io/github/oshai/kotlinlogging/Formatter.kt create mode 100644 src/directMain/kotlin/io/github/oshai/kotlinlogging/KLoggingEvent.kt create mode 100644 src/directMain/kotlin/io/github/oshai/kotlinlogging/KotlinLoggingConfiguration.kt rename src/{nativeMain => directMain}/kotlin/io/github/oshai/kotlinlogging/KotlinLoggingLevel.kt (100%) rename src/{jsMain => directMain}/kotlin/io/github/oshai/kotlinlogging/internal/ErrorMessageProducer.kt (100%) create mode 100644 src/directMain/kotlin/io/github/oshai/kotlinlogging/internal/KLoggerDirect.kt rename src/{nativeMain => directMain}/kotlin/io/github/oshai/kotlinlogging/internal/KLoggerFactory.kt (68%) delete mode 100644 src/jsMain/kotlin/io/github/oshai/kotlinlogging/Appender.kt delete mode 100644 src/jsMain/kotlin/io/github/oshai/kotlinlogging/DefaultMessageFormatter.kt delete mode 100644 src/jsMain/kotlin/io/github/oshai/kotlinlogging/Formatter.kt delete mode 100644 src/jsMain/kotlin/io/github/oshai/kotlinlogging/KotlinLoggingLevel.kt delete mode 100644 src/jsMain/kotlin/io/github/oshai/kotlinlogging/internal/KLoggerFactory.kt delete mode 100644 src/jsMain/kotlin/io/github/oshai/kotlinlogging/internal/KLoggerJS.kt delete mode 100644 src/nativeMain/kotlin/io/github/oshai/kotlinlogging/Appender.kt delete mode 100644 src/nativeMain/kotlin/io/github/oshai/kotlinlogging/DefaultMessageFormatter.kt delete mode 100644 src/nativeMain/kotlin/io/github/oshai/kotlinlogging/Formatter.kt delete mode 100644 src/nativeMain/kotlin/io/github/oshai/kotlinlogging/internal/ErrorMessageProducer.kt delete mode 100644 src/nativeMain/kotlin/io/github/oshai/kotlinlogging/internal/KLoggerNative.kt diff --git a/build.gradle.kts b/build.gradle.kts index 16e42ebf..d9d2860c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -146,16 +146,19 @@ kotlin { implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:${extra["coroutines_version"]}") } } - val jsMain by getting { + val directMain by creating { dependsOn(commonMain) } + val jsMain by getting { + dependsOn(directMain) + } val jsTest by getting { dependencies { implementation(kotlin("test-js")) } } val nativeMain by creating { - dependsOn(commonMain) + dependsOn(directMain) } val nativeTest by creating { dependencies { diff --git a/src/directMain/kotlin/io/github/oshai/kotlinlogging/Appender.kt b/src/directMain/kotlin/io/github/oshai/kotlinlogging/Appender.kt new file mode 100644 index 00000000..5d56b226 --- /dev/null +++ b/src/directMain/kotlin/io/github/oshai/kotlinlogging/Appender.kt @@ -0,0 +1,14 @@ +package io.github.oshai.kotlinlogging + +public interface Appender { + public fun log(loggingEvent: KLoggingEvent) +} + +public abstract class FormattingAppender : Appender { + public abstract fun logFormattedMessage(loggingEvent: KLoggingEvent, formattedMessage: Any?) + override fun log(loggingEvent: KLoggingEvent) { + KotlinLoggingConfiguration.formatter.formatMessage(loggingEvent).let { + logFormattedMessage(loggingEvent, it) + } + } +} diff --git a/src/directMain/kotlin/io/github/oshai/kotlinlogging/Formatter.kt b/src/directMain/kotlin/io/github/oshai/kotlinlogging/Formatter.kt new file mode 100644 index 00000000..ab92ac5d --- /dev/null +++ b/src/directMain/kotlin/io/github/oshai/kotlinlogging/Formatter.kt @@ -0,0 +1,44 @@ +package io.github.oshai.kotlinlogging + +public interface Formatter { + + public fun formatMessage(loggingEvent: KLoggingEvent): String +} + +public class DefaultMessageFormatter(private val includePrefix: Boolean = true) : Formatter { + + override fun formatMessage(loggingEvent: KLoggingEvent): String { + with(loggingEvent) { + return buildString { + append(prefix(level, loggerName)) + marker?.getName()?.let { + append(it) + append(" ") + } + append(message) + append(cause.throwableToString()) + } + } + } + + private fun prefix(level: Level, 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 + } +} diff --git a/src/directMain/kotlin/io/github/oshai/kotlinlogging/KLoggingEvent.kt b/src/directMain/kotlin/io/github/oshai/kotlinlogging/KLoggingEvent.kt new file mode 100644 index 00000000..427f5396 --- /dev/null +++ b/src/directMain/kotlin/io/github/oshai/kotlinlogging/KLoggingEvent.kt @@ -0,0 +1,24 @@ +package io.github.oshai.kotlinlogging + +public data class KLoggingEvent( + public val level: Level, + public val marker: Marker?, + public val loggerName: String, + public val message: String? = null, + public val cause: Throwable? = null, + public val payload: Map? = null, +) { + public constructor( + level: Level, + marker: Marker?, + loggerName: String, + eventBuilder: KLoggingEventBuilder + ) : this( + level, + marker, + loggerName, + eventBuilder.message, + eventBuilder.cause, + eventBuilder.payload + ) +} diff --git a/src/directMain/kotlin/io/github/oshai/kotlinlogging/KotlinLoggingConfiguration.kt b/src/directMain/kotlin/io/github/oshai/kotlinlogging/KotlinLoggingConfiguration.kt new file mode 100644 index 00000000..4dcff99e --- /dev/null +++ b/src/directMain/kotlin/io/github/oshai/kotlinlogging/KotlinLoggingConfiguration.kt @@ -0,0 +1,7 @@ +package io.github.oshai.kotlinlogging + +public expect object KotlinLoggingConfiguration { + public var logLevel: Level + public var formatter: Formatter + public var appender: Appender +} diff --git a/src/nativeMain/kotlin/io/github/oshai/kotlinlogging/KotlinLoggingLevel.kt b/src/directMain/kotlin/io/github/oshai/kotlinlogging/KotlinLoggingLevel.kt similarity index 100% rename from src/nativeMain/kotlin/io/github/oshai/kotlinlogging/KotlinLoggingLevel.kt rename to src/directMain/kotlin/io/github/oshai/kotlinlogging/KotlinLoggingLevel.kt diff --git a/src/jsMain/kotlin/io/github/oshai/kotlinlogging/internal/ErrorMessageProducer.kt b/src/directMain/kotlin/io/github/oshai/kotlinlogging/internal/ErrorMessageProducer.kt similarity index 100% rename from src/jsMain/kotlin/io/github/oshai/kotlinlogging/internal/ErrorMessageProducer.kt rename to src/directMain/kotlin/io/github/oshai/kotlinlogging/internal/ErrorMessageProducer.kt diff --git a/src/directMain/kotlin/io/github/oshai/kotlinlogging/internal/KLoggerDirect.kt b/src/directMain/kotlin/io/github/oshai/kotlinlogging/internal/KLoggerDirect.kt new file mode 100644 index 00000000..a2a00513 --- /dev/null +++ b/src/directMain/kotlin/io/github/oshai/kotlinlogging/internal/KLoggerDirect.kt @@ -0,0 +1,28 @@ +package io.github.oshai.kotlinlogging.internal + +import io.github.oshai.kotlinlogging.KLogger +import io.github.oshai.kotlinlogging.KLoggingEvent +import io.github.oshai.kotlinlogging.KLoggingEventBuilder +import io.github.oshai.kotlinlogging.KotlinLoggingConfiguration +import io.github.oshai.kotlinlogging.Level +import io.github.oshai.kotlinlogging.Level.OFF +import io.github.oshai.kotlinlogging.Marker +import io.github.oshai.kotlinlogging.isLoggingEnabled + +internal class KLoggerDirect(override val name: String) : KLogger { + + override fun at(level: Level, marker: Marker?, block: KLoggingEventBuilder.() -> Unit) { + if (isLoggingEnabledFor(level, marker)) { + KLoggingEventBuilder().apply(block).run { + when (level) { + OFF -> Unit + else -> KotlinLoggingConfiguration.appender.log(KLoggingEvent(level, marker, name, this)) + } + } + } + } + + override fun isLoggingEnabledFor(level: Level, marker: Marker?): Boolean { + return level.isLoggingEnabled() + } +} diff --git a/src/nativeMain/kotlin/io/github/oshai/kotlinlogging/internal/KLoggerFactory.kt b/src/directMain/kotlin/io/github/oshai/kotlinlogging/internal/KLoggerFactory.kt similarity index 68% rename from src/nativeMain/kotlin/io/github/oshai/kotlinlogging/internal/KLoggerFactory.kt rename to src/directMain/kotlin/io/github/oshai/kotlinlogging/internal/KLoggerFactory.kt index 568fdbd0..b866658a 100644 --- a/src/nativeMain/kotlin/io/github/oshai/kotlinlogging/internal/KLoggerFactory.kt +++ b/src/directMain/kotlin/io/github/oshai/kotlinlogging/internal/KLoggerFactory.kt @@ -4,5 +4,5 @@ import io.github.oshai.kotlinlogging.KLogger internal actual object KLoggerFactory { - actual fun logger(name: String): KLogger = KLoggerNative(name) + actual fun logger(name: String): KLogger = KLoggerDirect(name) } diff --git a/src/jsMain/kotlin/io/github/oshai/kotlinlogging/Appender.kt b/src/jsMain/kotlin/io/github/oshai/kotlinlogging/Appender.kt deleted file mode 100644 index 4fcb87a8..00000000 --- a/src/jsMain/kotlin/io/github/oshai/kotlinlogging/Appender.kt +++ /dev/null @@ -1,9 +0,0 @@ -package io.github.oshai.kotlinlogging - -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?) -} diff --git a/src/jsMain/kotlin/io/github/oshai/kotlinlogging/ConsoleOutputAppender.kt b/src/jsMain/kotlin/io/github/oshai/kotlinlogging/ConsoleOutputAppender.kt index 4a4806bf..5240cd89 100644 --- a/src/jsMain/kotlin/io/github/oshai/kotlinlogging/ConsoleOutputAppender.kt +++ b/src/jsMain/kotlin/io/github/oshai/kotlinlogging/ConsoleOutputAppender.kt @@ -1,9 +1,14 @@ package io.github.oshai.kotlinlogging -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 class ConsoleOutputAppender : FormattingAppender() { + override fun logFormattedMessage(loggingEvent: KLoggingEvent, formattedMessage: Any?) { + when (loggingEvent.level) { + Level.TRACE -> console.log(formattedMessage) + Level.DEBUG -> console.log(formattedMessage) + Level.INFO -> console.info(formattedMessage) + Level.WARN -> console.warn(formattedMessage) + Level.ERROR -> console.error(formattedMessage) + Level.OFF -> Unit + } + } } diff --git a/src/jsMain/kotlin/io/github/oshai/kotlinlogging/DefaultMessageFormatter.kt b/src/jsMain/kotlin/io/github/oshai/kotlinlogging/DefaultMessageFormatter.kt deleted file mode 100644 index 0da96047..00000000 --- a/src/jsMain/kotlin/io/github/oshai/kotlinlogging/DefaultMessageFormatter.kt +++ /dev/null @@ -1,40 +0,0 @@ -package io.github.oshai.kotlinlogging - -import io.github.oshai.kotlinlogging.internal.toStringSafe - -public object DefaultMessageFormatter : Formatter { - - public override fun formatMessage( - level: Level, - loggerName: String, - marker: Marker?, - throwable: Throwable?, - message: () -> Any? - ): String { - return buildString { - append(level.name) - append(": [") - append(loggerName) - append("] ") - marker?.getName()?.let { - append(it) - append(" ") - } - append(message.toStringSafe()) - append(throwable.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 - } -} diff --git a/src/jsMain/kotlin/io/github/oshai/kotlinlogging/Formatter.kt b/src/jsMain/kotlin/io/github/oshai/kotlinlogging/Formatter.kt deleted file mode 100644 index 0d26368e..00000000 --- a/src/jsMain/kotlin/io/github/oshai/kotlinlogging/Formatter.kt +++ /dev/null @@ -1,11 +0,0 @@ -package io.github.oshai.kotlinlogging - -public interface Formatter { - public fun formatMessage( - level: Level, - loggerName: String, - marker: Marker?, - throwable: Throwable?, - message: () -> Any? - ): Any? -} diff --git a/src/jsMain/kotlin/io/github/oshai/kotlinlogging/KotlinLoggingConfiguration.kt b/src/jsMain/kotlin/io/github/oshai/kotlinlogging/KotlinLoggingConfiguration.kt index 12cd3e42..18489c3d 100644 --- a/src/jsMain/kotlin/io/github/oshai/kotlinlogging/KotlinLoggingConfiguration.kt +++ b/src/jsMain/kotlin/io/github/oshai/kotlinlogging/KotlinLoggingConfiguration.kt @@ -1,7 +1,20 @@ package io.github.oshai.kotlinlogging -public object KotlinLoggingConfiguration { - public var LOG_LEVEL: Level = Level.INFO - public var APPENDER: Appender = ConsoleOutputAppender - public var FORMATTER: Formatter = DefaultMessageFormatter +public actual object KotlinLoggingConfiguration { + public actual var logLevel: Level = Level.INFO + public actual var formatter: Formatter = DefaultMessageFormatter(includePrefix = true) + public actual var appender: Appender = ConsoleOutputAppender() + + @Deprecated("Use appender instead", ReplaceWith("appender")) + public var APPENDER: Appender + get() = appender + set(value) { + appender = value + } + @Deprecated("Use logLevel instead", ReplaceWith("logLevel")) + public var LOG_LEVEL: Level + get() = logLevel + set(value) { + logLevel = value + } } diff --git a/src/jsMain/kotlin/io/github/oshai/kotlinlogging/KotlinLoggingLevel.kt b/src/jsMain/kotlin/io/github/oshai/kotlinlogging/KotlinLoggingLevel.kt deleted file mode 100644 index afe7a3dd..00000000 --- a/src/jsMain/kotlin/io/github/oshai/kotlinlogging/KotlinLoggingLevel.kt +++ /dev/null @@ -1,5 +0,0 @@ -package io.github.oshai.kotlinlogging - -import io.github.oshai.kotlinlogging.KotlinLoggingConfiguration.LOG_LEVEL - -public fun Level.isLoggingEnabled(): Boolean = this.ordinal >= LOG_LEVEL.ordinal diff --git a/src/jsMain/kotlin/io/github/oshai/kotlinlogging/internal/KLoggerFactory.kt b/src/jsMain/kotlin/io/github/oshai/kotlinlogging/internal/KLoggerFactory.kt deleted file mode 100644 index 8564e19f..00000000 --- a/src/jsMain/kotlin/io/github/oshai/kotlinlogging/internal/KLoggerFactory.kt +++ /dev/null @@ -1,8 +0,0 @@ -package io.github.oshai.kotlinlogging.internal - -import io.github.oshai.kotlinlogging.KLogger - -internal actual object KLoggerFactory { - - actual fun logger(name: String): KLogger = KLoggerJS(name) -} diff --git a/src/jsMain/kotlin/io/github/oshai/kotlinlogging/internal/KLoggerJS.kt b/src/jsMain/kotlin/io/github/oshai/kotlinlogging/internal/KLoggerJS.kt deleted file mode 100644 index 438bbcb1..00000000 --- a/src/jsMain/kotlin/io/github/oshai/kotlinlogging/internal/KLoggerJS.kt +++ /dev/null @@ -1,37 +0,0 @@ -package io.github.oshai.kotlinlogging.internal - -import io.github.oshai.kotlinlogging.KLogger -import io.github.oshai.kotlinlogging.KLoggingEventBuilder -import io.github.oshai.kotlinlogging.KotlinLoggingConfiguration.APPENDER -import io.github.oshai.kotlinlogging.KotlinLoggingConfiguration.FORMATTER -import io.github.oshai.kotlinlogging.Level -import io.github.oshai.kotlinlogging.Level.DEBUG -import io.github.oshai.kotlinlogging.Level.ERROR -import io.github.oshai.kotlinlogging.Level.INFO -import io.github.oshai.kotlinlogging.Level.OFF -import io.github.oshai.kotlinlogging.Level.TRACE -import io.github.oshai.kotlinlogging.Level.WARN -import io.github.oshai.kotlinlogging.Marker -import io.github.oshai.kotlinlogging.isLoggingEnabled - -internal class KLoggerJS(override val name: String) : KLogger { - - override fun at(level: Level, marker: Marker?, block: KLoggingEventBuilder.() -> Unit) { - if (isLoggingEnabledFor(level, marker)) { - KLoggingEventBuilder().apply(block).run { - when (level) { - TRACE -> APPENDER.trace(FORMATTER.formatMessage(level, name, marker, cause) { message }) - DEBUG -> APPENDER.debug(FORMATTER.formatMessage(level, name, marker, cause) { message }) - INFO -> APPENDER.info(FORMATTER.formatMessage(level, name, marker, cause) { message }) - WARN -> APPENDER.warn(FORMATTER.formatMessage(level, name, marker, cause) { message }) - ERROR -> APPENDER.error(FORMATTER.formatMessage(level, name, marker, cause) { message }) - OFF -> Unit - } - } - } - } - - override fun isLoggingEnabledFor(level: Level, marker: Marker?): Boolean { - return level.isLoggingEnabled() - } -} diff --git a/src/jsTest/kotlin/io/github/oshai/kotlinlogging/SimpleJsTest.kt b/src/jsTest/kotlin/io/github/oshai/kotlinlogging/SimpleJsTest.kt index ad2f4b08..6c3f9b7f 100644 --- a/src/jsTest/kotlin/io/github/oshai/kotlinlogging/SimpleJsTest.kt +++ b/src/jsTest/kotlin/io/github/oshai/kotlinlogging/SimpleJsTest.kt @@ -15,7 +15,7 @@ class SimpleJsTest { @AfterTest fun cleanup() { - KotlinLoggingConfiguration.APPENDER = ConsoleOutputAppender + KotlinLoggingConfiguration.APPENDER = ConsoleOutputAppender() KotlinLoggingConfiguration.LOG_LEVEL = Level.INFO } @@ -47,29 +47,9 @@ class SimpleJsTest { var lastMessage: String = "NA" var lastLevel: String = "NA" - override fun trace(message: Any?) { - lastMessage = message.toString() - lastLevel = "trace" - } - - override fun debug(message: Any?) { - lastMessage = message.toString() - lastLevel = "debug" - } - - override fun info(message: Any?) { - lastMessage = message.toString() - lastLevel = "info" - } - - override fun warn(message: Any?) { - lastMessage = message.toString() - lastLevel = "warn" - } - - override fun error(message: Any?) { - lastMessage = message.toString() - lastLevel = "error" + override fun log(loggingEvent: KLoggingEvent) { + lastMessage = DefaultMessageFormatter(includePrefix = true).formatMessage(loggingEvent) + lastLevel = loggingEvent.level.name.toLowerCase() } } } diff --git a/src/nativeMain/kotlin/io/github/oshai/kotlinlogging/Appender.kt b/src/nativeMain/kotlin/io/github/oshai/kotlinlogging/Appender.kt deleted file mode 100644 index 72fae92b..00000000 --- a/src/nativeMain/kotlin/io/github/oshai/kotlinlogging/Appender.kt +++ /dev/null @@ -1,11 +0,0 @@ -package io.github.oshai.kotlinlogging - -public interface Appender { - 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) -} diff --git a/src/nativeMain/kotlin/io/github/oshai/kotlinlogging/ConsoleOutputAppender.kt b/src/nativeMain/kotlin/io/github/oshai/kotlinlogging/ConsoleOutputAppender.kt index a8f4c0e5..a51ed3c0 100644 --- a/src/nativeMain/kotlin/io/github/oshai/kotlinlogging/ConsoleOutputAppender.kt +++ b/src/nativeMain/kotlin/io/github/oshai/kotlinlogging/ConsoleOutputAppender.kt @@ -3,14 +3,12 @@ package io.github.oshai.kotlinlogging 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 fun error(loggerName: String, message: String) { - fprintf(stderr, "$message\n") +public object ConsoleOutputAppender : FormattingAppender() { + override fun logFormattedMessage(loggingEvent: KLoggingEvent, formattedMessage: Any?) { + if (loggingEvent.level == Level.ERROR) { + fprintf(stderr, "$formattedMessage\n") + } else { + println(formattedMessage) + } } } diff --git a/src/nativeMain/kotlin/io/github/oshai/kotlinlogging/DefaultMessageFormatter.kt b/src/nativeMain/kotlin/io/github/oshai/kotlinlogging/DefaultMessageFormatter.kt deleted file mode 100644 index bf054463..00000000 --- a/src/nativeMain/kotlin/io/github/oshai/kotlinlogging/DefaultMessageFormatter.kt +++ /dev/null @@ -1,37 +0,0 @@ -package io.github.oshai.kotlinlogging - -import io.github.oshai.kotlinlogging.internal.toStringSafe - -public object DefaultMessageFormatter : Formatter { - - public override fun formatMessage( - includePrefix: Boolean, - level: Level, - 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: Level, 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 - } -} diff --git a/src/nativeMain/kotlin/io/github/oshai/kotlinlogging/Formatter.kt b/src/nativeMain/kotlin/io/github/oshai/kotlinlogging/Formatter.kt deleted file mode 100644 index a6ce341f..00000000 --- a/src/nativeMain/kotlin/io/github/oshai/kotlinlogging/Formatter.kt +++ /dev/null @@ -1,13 +0,0 @@ -package io.github.oshai.kotlinlogging - -public interface Formatter { - - public fun formatMessage( - includePrefix: Boolean, - level: Level, - loggerName: String, - marker: Marker?, - t: Throwable?, - msg: () -> Any? - ): String -} diff --git a/src/nativeMain/kotlin/io/github/oshai/kotlinlogging/KotlinLoggingConfiguration.kt b/src/nativeMain/kotlin/io/github/oshai/kotlinlogging/KotlinLoggingConfiguration.kt index b30aaae7..9ca99631 100644 --- a/src/nativeMain/kotlin/io/github/oshai/kotlinlogging/KotlinLoggingConfiguration.kt +++ b/src/nativeMain/kotlin/io/github/oshai/kotlinlogging/KotlinLoggingConfiguration.kt @@ -4,21 +4,21 @@ import kotlin.native.concurrent.AtomicReference public expect val DefaultAppender: Appender -public object KotlinLoggingConfiguration { +public actual object KotlinLoggingConfiguration { private val _logLevel = AtomicReference(Level.INFO) - public var logLevel: Level + public actual var logLevel: Level get() = _logLevel.value set(value) { _logLevel.value = value } private val _appender = AtomicReference(DefaultAppender) - public var appender: Appender + public actual var appender: Appender get() = _appender.value set(value) { _appender.value = value } - private val _formatter = AtomicReference(DefaultMessageFormatter) - public var formatter: Formatter + private val _formatter = AtomicReference(DefaultMessageFormatter(includePrefix = true)) + public actual var formatter: Formatter get() = _formatter.value set(value) { _formatter.value = value diff --git a/src/nativeMain/kotlin/io/github/oshai/kotlinlogging/internal/ErrorMessageProducer.kt b/src/nativeMain/kotlin/io/github/oshai/kotlinlogging/internal/ErrorMessageProducer.kt deleted file mode 100644 index 6d35a773..00000000 --- a/src/nativeMain/kotlin/io/github/oshai/kotlinlogging/internal/ErrorMessageProducer.kt +++ /dev/null @@ -1,3 +0,0 @@ -package io.github.oshai.kotlinlogging.internal - -internal actual typealias ErrorMessageProducer = DefaultErrorMessageProducer diff --git a/src/nativeMain/kotlin/io/github/oshai/kotlinlogging/internal/KLoggerNative.kt b/src/nativeMain/kotlin/io/github/oshai/kotlinlogging/internal/KLoggerNative.kt deleted file mode 100644 index 8db7a033..00000000 --- a/src/nativeMain/kotlin/io/github/oshai/kotlinlogging/internal/KLoggerNative.kt +++ /dev/null @@ -1,36 +0,0 @@ -package io.github.oshai.kotlinlogging.internal - -import io.github.oshai.kotlinlogging.KLogger -import io.github.oshai.kotlinlogging.KLoggingEventBuilder -import io.github.oshai.kotlinlogging.KotlinLoggingConfiguration.appender -import io.github.oshai.kotlinlogging.KotlinLoggingConfiguration.formatter -import io.github.oshai.kotlinlogging.Level -import io.github.oshai.kotlinlogging.Level.* -import io.github.oshai.kotlinlogging.Marker -import io.github.oshai.kotlinlogging.isLoggingEnabled - -internal class KLoggerNative(override val name: String) : KLogger { - - override fun at(level: Level, marker: Marker?, block: KLoggingEventBuilder.() -> Unit) { - if (isLoggingEnabledFor(level, marker)) { - KLoggingEventBuilder().apply(block).run { - val formattedMessage = - formatter.formatMessage(appender.includePrefix, level, name, marker, this.cause) { - this.message - } - when (level) { - TRACE -> appender.trace(name, formattedMessage) - DEBUG -> appender.debug(name, formattedMessage) - INFO -> appender.info(name, formattedMessage) - WARN -> appender.warn(name, formattedMessage) - ERROR -> appender.error(name, formattedMessage) - OFF -> Unit - } - } - } - } - - override fun isLoggingEnabledFor(level: Level, marker: Marker?): Boolean { - return level.isLoggingEnabled() - } -} From 9b04fe98544c1ff74a633646748b9bbbece1fa0e Mon Sep 17 00:00:00 2001 From: oshai Date: Thu, 10 Aug 2023 09:50:23 +0300 Subject: [PATCH 22/26] bump version to 5.1.1 --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index d9d2860c..b100fd60 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -17,7 +17,7 @@ plugins { apply("versions.gradle.kts") group = "io.github.oshai" -version = "5.1.0" +version = "5.1.1" repositories { gradlePluginPortal() From a7caeef24ecbd392907d377a3120f4515d4ac5a9 Mon Sep 17 00:00:00 2001 From: Ohad Shai Date: Mon, 21 Aug 2023 19:25:12 +0300 Subject: [PATCH 23/26] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 49b06e63..2925724b 100644 --- a/README.md +++ b/README.md @@ -90,7 +90,7 @@ In short, if you just want to log statements to stdout, it's possible to add the io.github.oshai kotlin-logging-jvm - 5.0.1 + 5.1.0 ``` @@ -98,7 +98,7 @@ See the full example in [kotlin-logging-example-maven](https://github.com/oshai/ ### Gradle ```Groovy -implementation 'io.github.oshai:kotlin-logging-jvm:5.0.1' +implementation 'io.github.oshai:kotlin-logging-jvm:5.1.0' ``` From 4627e2a3b930e8e98fcd5f314a41eecf21aad4d5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 11 Sep 2023 05:15:33 +0000 Subject: [PATCH 24/26] Bump actions/checkout from 3 to 4 Bumps [actions/checkout](https://github.com/actions/checkout) from 3 to 4. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v3...v4) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/cd.yml | 2 +- .github/workflows/ci.yml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 3ea0d860..8e7fecb3 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -12,7 +12,7 @@ jobs: runs-on: macos-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Configure JDK uses: actions/setup-java@v3 with: diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ea02c8f0..54a29e50 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,7 +7,7 @@ jobs: name: "Validate Gradle Wrapper" runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: gradle/wrapper-validation-action@v1 build: name: Build on ${{ matrix.os.runner }} @@ -39,7 +39,7 @@ jobs: mingw-w64-x86_64-cmake mingw-w64-x86_64-extra-cmake-modules mingw64/mingw-w64-x86_64-cyrus-sasl - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Restore native cache id: cache-native From b329b85561ffb468d7b90a5de075ca10189f105d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 11 Sep 2023 05:15:37 +0000 Subject: [PATCH 25/26] Bump actions/cache from 3.3.1 to 3.3.2 Bumps [actions/cache](https://github.com/actions/cache) from 3.3.1 to 3.3.2. - [Release notes](https://github.com/actions/cache/releases) - [Changelog](https://github.com/actions/cache/blob/main/RELEASES.md) - [Commits](https://github.com/actions/cache/compare/v3.3.1...v3.3.2) --- updated-dependencies: - dependency-name: actions/cache dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 54a29e50..10d17963 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -43,7 +43,7 @@ jobs: - name: Restore native cache id: cache-native - uses: actions/cache@v3.3.1 + uses: actions/cache@v3.3.2 with: path: | scripts/build @@ -56,7 +56,7 @@ jobs: - name: Restore Gradle cache id: cache-gradle - uses: actions/cache@v3.3.1 + uses: actions/cache@v3.3.2 with: path: | ~/.gradle/caches From da65786494e8203cfbec61aceb13074ab8b0414a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 2 Oct 2023 05:48:54 +0000 Subject: [PATCH 26/26] Bump com.diffplug.spotless from 6.20.0 to 6.22.0 Bumps com.diffplug.spotless from 6.20.0 to 6.22.0. --- updated-dependencies: - dependency-name: com.diffplug.spotless dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index b100fd60..83b90e8f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -10,7 +10,7 @@ plugins { signing id("io.gitlab.arturbosch.detekt") version "1.18.0" id("com.android.library") version "7.4.2" - id("com.diffplug.spotless") version "6.20.0" + id("com.diffplug.spotless") version "6.22.0" }