Skip to content

Commit

Permalink
refactor: make lifecycle log output to have consistent indentation wi…
Browse files Browse the repository at this point in the history
…th other levels, just another visual update

Signed-off-by: Artyom Shendrik <artyom.shendrik@gmail.com>
  • Loading branch information
amal committed Jan 8, 2024
1 parent cfcc1ce commit 4357abd
Showing 1 changed file with 33 additions and 21 deletions.
54 changes: 33 additions & 21 deletions fluxo-kmp-conf/src/main/kotlin/fluxo/conf/impl/LoggerUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,26 @@ private const val TAG = "FluxoKmpConf"
internal var SHOW_DEBUG_LOGS = false


internal fun Logger.t(message: String) = when {
!SHOW_DEBUG_LOGS -> trace("{} {}", TAG, message)
else -> lifecycle("v: {}", message)
private const val V = "v: "
private const val D = "d: "
private const val I = "i: "
private const val L = " "
private const val W = "w: "
private const val E = "e: "


internal fun Logger.t(message: String) {
when {
SHOW_DEBUG_LOGS -> lifecycle("$V{}", message)
isTraceEnabled -> trace("{} {}", TAG, message)
}
}

internal fun Logger.t(message: String, e: Throwable?) = when {
!SHOW_DEBUG_LOGS -> trace("$TAG: $message", e)
else -> lifecycle("v: $message", e)
internal fun Logger.t(message: String, e: Throwable?) {
when {
SHOW_DEBUG_LOGS -> lifecycle("$V$message", e)
isTraceEnabled -> trace("$TAG: $message", e)
}
}

internal fun Logger.v(message: String) = t(message)
Expand All @@ -28,43 +40,43 @@ internal fun Logger.v(message: String, e: Throwable?) = t(message, e)

internal fun Logger.d(message: String, e: Throwable? = null) = when {
!SHOW_DEBUG_LOGS -> debug("$TAG: $message", e)
else -> lifecycle("d: $message", e)
else -> lifecycle("$D$message", e)
}

internal fun Logger.d(message: String, arg1: Any?, arg2: Any?) = when {
!SHOW_DEBUG_LOGS -> debug("$TAG: $message", arg1, arg2)
else -> lifecycle("d: $message", arg1, arg2)
else -> lifecycle("$D$message", arg1, arg2)
}

internal fun Logger.d(message: String, arg1: Any?, arg2: Any?, arg3: Any?) = when {
!SHOW_DEBUG_LOGS -> debug("$TAG: $message", arg1, arg2, arg3)
else -> lifecycle("d: $message", arg1, arg2, arg3)
else -> lifecycle("$D$message", arg1, arg2, arg3)
}


internal fun Logger.i(message: String) = when {
!SHOW_DEBUG_LOGS -> debug(message)
else -> lifecycle("i: {}", message)
!SHOW_DEBUG_LOGS -> info(message)
else -> lifecycle("$I{}", message)
}

internal fun Logger.i(message: String, arg1: Any?) = when {
!SHOW_DEBUG_LOGS -> debug(message, arg1)
else -> lifecycle("i: $message", arg1)
!SHOW_DEBUG_LOGS -> info(message, arg1)
else -> lifecycle("$I$message", arg1)
}


internal fun Logger.l(message: String) = lifecycle(message)
internal fun Logger.l(message: String, vararg args: Any) = lifecycle(message, *args)
internal fun Logger.l(message: String) = lifecycle(L + message)
internal fun Logger.l(message: String, vararg args: Any) = lifecycle(L + message, *args)


internal fun Logger.w(message: String) = warn("w: {}", message)
internal fun Logger.w(message: String, e: Throwable?) = warn("w: $message", e)
internal fun Logger.w(message: String) = warn("$W{}", message)
internal fun Logger.w(message: String, e: Throwable?) = warn("$W$message", e)


internal fun Logger.e(message: String) = error("e: {}", message)
internal fun Logger.e(message: String) = error("$E{}", message)

internal fun Logger.e(message: String, e: Throwable?) = error("e: $message", e)
internal fun Logger.e(message: String, e: Throwable?) = error("$E$message", e)

internal fun Logger.e(message: String, arg1: Any?) = error("e: $message", arg1)
internal fun Logger.e(message: String, arg1: Any?) = error("$E$message", arg1)

internal fun Logger.e(message: String, vararg args: Any?) = error("e: $message", *args)
internal fun Logger.e(message: String, vararg args: Any?) = error("$E$message", *args)

0 comments on commit 4357abd

Please sign in to comment.