add trace level

This commit is contained in:
InsanusMokrassar 2023-11-18 16:18:08 +06:00
parent 34a7c9624d
commit 7a8bd035f5
7 changed files with 34 additions and 2 deletions

View File

@ -2,6 +2,8 @@
## 1.2.5 ## 1.2.5
* Add `trace` logging level
## 1.2.4 ## 1.2.4
**This update contains migration onto gradle 8+ (for both wrapper and android plugin). Use it with caution** **This update contains migration onto gradle 8+ (for both wrapper and android plugin). Use it with caution**

View File

@ -1,9 +1,9 @@
[versions] [versions]
kotlin = "1.9.20" 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" dokka = "1.9.10"

View File

@ -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 -> internal actual val defaultLogging: (level: LogLevel, tag: String, message: Any, throwable: Throwable?) -> Unit = { l, t, m, e ->
val messageString = m.toString() val messageString = m.toString()
when(l) { when(l) {
LogLevel.TRACE -> Log.d(t, messageString, e)
LogLevel.DEBUG -> Log.d(t, messageString, e) LogLevel.DEBUG -> Log.d(t, messageString, e)
LogLevel.VERBOSE -> Log.v(t, messageString, e) LogLevel.VERBOSE -> Log.v(t, messageString, e)
LogLevel.INFO -> Log.i(t, messageString, e) LogLevel.INFO -> Log.i(t, messageString, e)

View File

@ -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.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(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?, 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) 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.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(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?, e: Throwable? = null, noinline messageBuilder: () -> Any) = debug(tag, e, messageBuilder)
inline fun KSLog.d(tag: String, noinline messageBuilder: () -> Any) = d(tag, null, messageBuilder) inline fun KSLog.d(tag: String, noinline messageBuilder: () -> Any) = d(tag, null, messageBuilder)

View File

@ -5,6 +5,7 @@ import dev.inmo.kslog.common.utils.plus
enum class LogLevel { enum class LogLevel {
TRACE,
DEBUG, DEBUG,
VERBOSE, VERBOSE,
INFO, INFO,

View File

@ -5,6 +5,7 @@ internal actual val defaultLogging: (level: LogLevel, tag: String, message: Any,
arrayOf(m, e) arrayOf(m, e)
} ?: arrayOf(m) } ?: arrayOf(m)
when (l) { when (l) {
LogLevel.TRACE,
LogLevel.DEBUG -> console.log(*args) LogLevel.DEBUG -> console.log(*args)
LogLevel.VERBOSE, LogLevel.VERBOSE,
LogLevel.INFO -> console.info(*args) LogLevel.INFO -> console.info(*args)

View File

@ -11,6 +11,7 @@ private fun Logger.doLog(
l: LogLevel, t: String, m: String, e: Throwable? l: LogLevel, t: String, m: String, e: Throwable?
) = log( ) = log(
when(l) { when(l) {
LogLevel.TRACE -> Level.ALL
LogLevel.DEBUG -> Level.FINEST LogLevel.DEBUG -> Level.FINEST
LogLevel.VERBOSE -> Level.FINE LogLevel.VERBOSE -> Level.FINE
LogLevel.INFO -> Level.INFO LogLevel.INFO -> Level.INFO