mirror of
https://github.com/InsanusMokrassar/KSLog.git
synced 2024-11-13 03:33:47 +00:00
28 lines
855 B
Kotlin
28 lines
855 B
Kotlin
|
package truth.simple.kmp.logger.common
|
||
|
|
||
|
fun Logger(
|
||
|
messageFormatter: (l: LogLevel, m: String, t: String?, Throwable?) -> String,
|
||
|
filter: (l: LogLevel, m: String, t: String?, Throwable?) -> Boolean
|
||
|
) = Logger { l, m, t, e ->
|
||
|
if (!filter(l, m, t, e)) return@Logger
|
||
|
val text = messageFormatter(l,m,t,e)
|
||
|
when (l) {
|
||
|
LogLevel.VERBOSE,
|
||
|
LogLevel.INFO -> console.info(text, e)
|
||
|
LogLevel.WARNING -> console.warn(text, e)
|
||
|
LogLevel.ERROR,
|
||
|
LogLevel.ASSERT -> console.error(text, e)
|
||
|
LogLevel.DEBUG -> console.log(text, e)
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
actual fun Logger(
|
||
|
defaultTag: String,
|
||
|
filter: (l: LogLevel, m: String, t: String, Throwable?) -> Boolean
|
||
|
): Logger {
|
||
|
return Logger(
|
||
|
{ l, m, t, e -> "[$l] ${t ?: defaultTag} - $m" },
|
||
|
{ l, m, t, e -> filter(l, m, t ?: defaultTag, e) }
|
||
|
)
|
||
|
}
|