mirror of
https://github.com/InsanusMokrassar/KSLog.git
synced 2026-01-15 00:19:19 +00:00
a lot of changes and improvements
This commit is contained in:
@@ -1,16 +0,0 @@
|
||||
package dev.inmo.kslog.common
|
||||
|
||||
internal actual val defaultLogging: (level: LogLevel, tag: String, message: Any, throwable: Throwable?) -> Unit = { l, t, m, e ->
|
||||
val args = e ?.let {
|
||||
arrayOf(m, e)
|
||||
} ?: arrayOf(m)
|
||||
when (l) {
|
||||
LogLevel.TRACE,
|
||||
LogLevel.DEBUG -> console.log(*args)
|
||||
LogLevel.VERBOSE,
|
||||
LogLevel.INFO -> console.info(*args)
|
||||
LogLevel.WARNING -> console.warn(*args)
|
||||
LogLevel.ERROR,
|
||||
LogLevel.ASSERT -> console.error(*args)
|
||||
}
|
||||
}
|
||||
24
src/jsMain/kotlin/ExtendedConsole.kt
Normal file
24
src/jsMain/kotlin/ExtendedConsole.kt
Normal file
@@ -0,0 +1,24 @@
|
||||
package dev.inmo.kslog.common
|
||||
|
||||
import kotlin.js.Console
|
||||
|
||||
external interface ExtendedConsole : Console {
|
||||
fun trace()
|
||||
fun debug(vararg o: Any?)
|
||||
fun assert(vararg o: Any?)
|
||||
}
|
||||
|
||||
/**
|
||||
* [https://developer.mozilla.org/en-US/docs/Web/API/console/debug_static](https://developer.mozilla.org/en-US/docs/Web/API/console/debug_static)
|
||||
*/
|
||||
fun Console.debug(vararg args: Any?) = unsafeCast<ExtendedConsole>().debug(*args)
|
||||
|
||||
/**
|
||||
* [https://developer.mozilla.org/en-US/docs/Web/APtraceI/console/assert_static](https://developer.mozilla.org/en-US/docs/Web/API/console/assert_static)
|
||||
*/
|
||||
fun Console.assert(vararg args: Any?) = unsafeCast<ExtendedConsole>().assert(*args)
|
||||
|
||||
/**
|
||||
* [https://developer.mozilla.org/en-US/docs/Web/API/console/trace_static](https://developer.mozilla.org/en-US/docs/Web/API/console/trace_static)
|
||||
*/
|
||||
fun Console.trace() = unsafeCast<ExtendedConsole>().trace()
|
||||
19
src/jsMain/kotlin/KSLoggerDefaultPlatformLoggerLambda.kt
Normal file
19
src/jsMain/kotlin/KSLoggerDefaultPlatformLoggerLambda.kt
Normal file
@@ -0,0 +1,19 @@
|
||||
package dev.inmo.kslog.common
|
||||
|
||||
actual var KSLoggerDefaultPlatformLoggerLambda: (level: LogLevel, tag: String, message: Any, throwable: Throwable?) -> Unit = { l, _, m, e ->
|
||||
val args = e ?.let {
|
||||
arrayOf(m, e)
|
||||
} ?: arrayOf(m)
|
||||
when (l) {
|
||||
LogLevel.TRACE -> {
|
||||
console.trace()
|
||||
console.debug(*args)
|
||||
}
|
||||
LogLevel.DEBUG -> console.debug(*args)
|
||||
LogLevel.VERBOSE,
|
||||
LogLevel.INFO -> console.info(*args)
|
||||
LogLevel.WARNING -> console.warn(*args)
|
||||
LogLevel.ERROR -> console.error(*args)
|
||||
LogLevel.ASSERT -> console.assert(*args)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user