From 7a8bd035f5af2070dff93b6e7309a985bc27233d Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 18 Nov 2023 16:18:08 +0600 Subject: [PATCH] add trace level --- CHANGELOG.md | 2 ++ gradle/libs.versions.toml | 4 ++-- src/androidMain/kotlin/ActualLogger.kt | 1 + src/commonMain/kotlin/Extensions.kt | 26 ++++++++++++++++++++++++++ src/commonMain/kotlin/KSLog.kt | 1 + src/jsMain/kotlin/ActualLogger.kt | 1 + src/jvmMain/kotlin/ActualLogger.kt | 1 + 7 files changed, 34 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7424592..ae43510 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## 1.2.5 +* Add `trace` logging level + ## 1.2.4 **This update contains migration onto gradle 8+ (for both wrapper and android plugin). Use it with caution** diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 972c8f1..fd5bf12 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,9 +1,9 @@ [versions] kotlin = "1.9.20" -kotlin-gradle-plugin = "8.1.2" +kotlin-gradle-plugin = "8.1.4" -versions = "0.49.0" +versions = "0.50.0" dokka = "1.9.10" diff --git a/src/androidMain/kotlin/ActualLogger.kt b/src/androidMain/kotlin/ActualLogger.kt index 8a37e03..8020f08 100644 --- a/src/androidMain/kotlin/ActualLogger.kt +++ b/src/androidMain/kotlin/ActualLogger.kt @@ -6,6 +6,7 @@ import android.util.Log internal actual val defaultLogging: (level: LogLevel, tag: String, message: Any, throwable: Throwable?) -> Unit = { l, t, m, e -> val messageString = m.toString() when(l) { + LogLevel.TRACE -> Log.d(t, messageString, e) LogLevel.DEBUG -> Log.d(t, messageString, e) LogLevel.VERBOSE -> Log.v(t, messageString, e) LogLevel.INFO -> Log.i(t, messageString, e) diff --git a/src/commonMain/kotlin/Extensions.kt b/src/commonMain/kotlin/Extensions.kt index ae73e61..4110a9c 100644 --- a/src/commonMain/kotlin/Extensions.kt +++ b/src/commonMain/kotlin/Extensions.kt @@ -15,6 +15,19 @@ inline fun KSLog.log(level: LogLevel, tag: String, message: Any, e: Throwable?) inline fun KSLog.log(level: LogLevel, tag: String, message: Any) = performLog(level, tag, message, null) +inline fun KSLog.trace(e: Throwable? = null, noinline messageBuilder: () -> Any) = log(LogLevel.TRACE, null, e, messageBuilder) +inline fun KSLog.trace(tag: String?, e: Throwable? = null, noinline messageBuilder: () -> Any) = log(LogLevel.TRACE, tag, e, messageBuilder) +inline fun KSLog.trace(tag: String, noinline messageBuilder: () -> Any) = trace(tag, null, messageBuilder) +suspend inline fun KSLog.traceS(e: Throwable? = null, noinline messageBuilder: suspend () -> Any) = logS(LogLevel.TRACE, null, e, messageBuilder) +suspend inline fun KSLog.traceS(tag: String?, e: Throwable? = null, noinline messageBuilder: suspend () -> Any) = logS(LogLevel.TRACE, tag, e, messageBuilder) +suspend inline fun KSLog.traceS(tag: String, noinline messageBuilder: suspend () -> Any) = traceS(tag, null, messageBuilder) +inline fun KSLog.trace(message: Any, e: Throwable?) = log(LogLevel.TRACE, message, e) +inline fun KSLog.trace(message: String, e: Throwable) = trace(message as Any, e) +inline fun KSLog.trace(message: Any) = trace(message, null) +inline fun KSLog.trace(tag: String, message: Any, e: Throwable?) = log(LogLevel.TRACE, tag, message, e) +inline fun KSLog.trace(tag: String, message: Any) = trace(tag, message, null) + + inline fun KSLog.debug(e: Throwable? = null, noinline messageBuilder: () -> Any) = log(LogLevel.DEBUG, null, e, messageBuilder) inline fun KSLog.debug(tag: String?, e: Throwable? = null, noinline messageBuilder: () -> Any) = log(LogLevel.DEBUG, tag, e, messageBuilder) inline fun KSLog.debug(tag: String, noinline messageBuilder: () -> Any) = debug(tag, null, messageBuilder) @@ -108,6 +121,19 @@ inline fun KSLog.l(level: LogLevel, tag: String, message: Any, e: Throwable?) = inline fun KSLog.l(level: LogLevel, tag: String, message: Any) = log(level, tag, message, null) +inline fun KSLog.t(e: Throwable? = null, noinline messageBuilder: () -> Any) = trace(e, messageBuilder) +inline fun KSLog.t(tag: String?, e: Throwable? = null, noinline messageBuilder: () -> Any) = trace(tag, e, messageBuilder) +inline fun KSLog.t(tag: String, noinline messageBuilder: () -> Any) = t(tag, null, messageBuilder) +suspend inline fun KSLog.tS(e: Throwable? = null, noinline messageBuilder: suspend () -> Any) = traceS(e, messageBuilder) +suspend inline fun KSLog.tS(tag: String?, e: Throwable? = null, noinline messageBuilder: suspend () -> Any) = traceS(tag, e, messageBuilder) +suspend inline fun KSLog.tS(tag: String, noinline messageBuilder: suspend () -> Any) = tS(tag, null, messageBuilder) +inline fun KSLog.t(message: Any, e: Throwable?) = trace(message, e) +inline fun KSLog.t(message: String, e: Throwable) = t(message as Any, e) +inline fun KSLog.t(message: Any) = t(message, null) +inline fun KSLog.t(tag: String, message: Any, e: Throwable?) = trace(tag, message, e) +inline fun KSLog.t(tag: String, message: Any) = t(tag, message, null) + + inline fun KSLog.d(e: Throwable? = null, noinline messageBuilder: () -> Any) = debug(e, messageBuilder) inline fun KSLog.d(tag: String?, e: Throwable? = null, noinline messageBuilder: () -> Any) = debug(tag, e, messageBuilder) inline fun KSLog.d(tag: String, noinline messageBuilder: () -> Any) = d(tag, null, messageBuilder) diff --git a/src/commonMain/kotlin/KSLog.kt b/src/commonMain/kotlin/KSLog.kt index c00e141..3df22bb 100644 --- a/src/commonMain/kotlin/KSLog.kt +++ b/src/commonMain/kotlin/KSLog.kt @@ -5,6 +5,7 @@ import dev.inmo.kslog.common.utils.plus enum class LogLevel { + TRACE, DEBUG, VERBOSE, INFO, diff --git a/src/jsMain/kotlin/ActualLogger.kt b/src/jsMain/kotlin/ActualLogger.kt index c647d75..19ed996 100644 --- a/src/jsMain/kotlin/ActualLogger.kt +++ b/src/jsMain/kotlin/ActualLogger.kt @@ -5,6 +5,7 @@ internal actual val defaultLogging: (level: LogLevel, tag: String, message: Any, arrayOf(m, e) } ?: arrayOf(m) when (l) { + LogLevel.TRACE, LogLevel.DEBUG -> console.log(*args) LogLevel.VERBOSE, LogLevel.INFO -> console.info(*args) diff --git a/src/jvmMain/kotlin/ActualLogger.kt b/src/jvmMain/kotlin/ActualLogger.kt index aa3ac13..c0c1b1e 100644 --- a/src/jvmMain/kotlin/ActualLogger.kt +++ b/src/jvmMain/kotlin/ActualLogger.kt @@ -11,6 +11,7 @@ private fun Logger.doLog( l: LogLevel, t: String, m: String, e: Throwable? ) = log( when(l) { + LogLevel.TRACE -> Level.ALL LogLevel.DEBUG -> Level.FINEST LogLevel.VERBOSE -> Level.FINE LogLevel.INFO -> Level.INFO