KSLog/src/jsMain/kotlin/ActualLogger.kt

22 lines
602 B
Kotlin
Raw Normal View History

2022-06-07 14:02:59 +00:00
package dev.inmo.kslog.common
2022-06-07 13:26:11 +00:00
actual fun KSLog(
2022-06-08 12:23:11 +00:00
defaultTag: String,
filter: MessageFilter,
messageFormatter: MessageFormatter
): KSLog = KSLog { l, t, m, e ->
2022-06-07 15:42:19 +00:00
if (!filter(l, t, m, e)) return@KSLog
2022-06-08 12:23:11 +00:00
val text = messageFormatter(l, t?:defaultTag, m, e)
2022-06-07 15:52:42 +00:00
val args = e ?.let {
arrayOf(text, e)
} ?: arrayOf(text)
2022-06-07 13:26:11 +00:00
when (l) {
2022-06-08 15:45:37 +00:00
LogLevel.DEBUG -> console.log(*args)
2022-06-07 13:26:11 +00:00
LogLevel.VERBOSE,
2022-06-07 15:52:42 +00:00
LogLevel.INFO -> console.info(*args)
LogLevel.WARNING -> console.warn(*args)
2022-06-07 13:26:11 +00:00
LogLevel.ERROR,
2022-06-07 15:52:42 +00:00
LogLevel.ASSERT -> console.error(*args)
2022-06-07 13:26:11 +00:00
}
}