mirror of
https://github.com/InsanusMokrassar/KSLog.git
synced 2024-12-22 14:07:15 +00:00
switch case of default kslogger
This commit is contained in:
parent
7fec433344
commit
afad845108
@ -4,5 +4,5 @@ val Any.logTag
|
||||
get() = this::class.simpleName ?: error("Unable to retrieve log tag")
|
||||
val Any.logger
|
||||
get() = CallbackKSLog { l, t, m, e ->
|
||||
KSLog.DEFAULT.performLog(l, t ?: logTag, m, e)
|
||||
KSLog.default.performLog(l, t ?: logTag, m, e)
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ interface KSLog {
|
||||
fun performLog(level: LogLevel, tag: String?, message: String, throwable: Throwable?)
|
||||
companion object : KSLog {
|
||||
private var defaultLogger: KSLog? = null
|
||||
var DEFAULT: KSLog
|
||||
var default: KSLog
|
||||
get() {
|
||||
return defaultLogger ?: KSLog("app").also {
|
||||
defaultLogger = it
|
||||
@ -23,7 +23,7 @@ interface KSLog {
|
||||
set(value) {
|
||||
defaultLogger = value
|
||||
}
|
||||
override fun performLog(level: LogLevel, tag: String?, message: String, throwable: Throwable?) = DEFAULT.performLog(level, tag, message, throwable)
|
||||
override fun performLog(level: LogLevel, tag: String?, message: String, throwable: Throwable?) = default.performLog(level, tag, message, throwable)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,13 +6,16 @@ fun KSLog(
|
||||
) = KSLog { l, t, m, e ->
|
||||
if (!filter(l, t, m, e)) return@KSLog
|
||||
val text = messageFormatter(l,t,m,e)
|
||||
val args = e ?.let {
|
||||
arrayOf(text, e)
|
||||
} ?: arrayOf(text)
|
||||
when (l) {
|
||||
LogLevel.VERBOSE,
|
||||
LogLevel.INFO -> console.info(text, e)
|
||||
LogLevel.WARNING -> console.warn(text, e)
|
||||
LogLevel.INFO -> console.info(*args)
|
||||
LogLevel.WARNING -> console.warn(*args)
|
||||
LogLevel.ERROR,
|
||||
LogLevel.ASSERT -> console.error(text, e)
|
||||
LogLevel.DEBUG -> console.log(text, e)
|
||||
LogLevel.ASSERT -> console.error(*args)
|
||||
LogLevel.DEBUG -> console.log(*args)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user