generate kdocs

This commit is contained in:
2025-11-12 13:45:57 +06:00
parent 3c4e59ddc2
commit 7f92a3e614
16 changed files with 510 additions and 40 deletions

View File

@@ -2,23 +2,62 @@ package dev.inmo.kslog.common
import kotlin.js.Console
/**
* Extended Console interface that includes additional console methods
* not present in Kotlin's standard Console interface
*
* Provides access to browser/Node.js console methods like `debug`, `trace`, and `assert`.
*/
external interface ExtendedConsole : Console {
/**
* Outputs a stack trace to the console
*/
fun trace()
/**
* Outputs a debug message to the console
*
* @param o Objects to output
*/
fun debug(vararg o: Any?)
/**
* Writes an error message to the console if the assertion is false
*
* @param assertion Boolean condition to test
* @param o Objects to output if assertion is false
*/
fun assert(assertion: Boolean, 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)
* Extension function to output debug messages to the console
*
* Maps to the browser's `console.debug()` method.
*
* [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/console/debug_static)
*
* @param args Objects to output
*/
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)
* Extension function to write an error message if assertion fails
*
* Maps to the browser's `console.assert()` method.
*
* [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/console/assert_static)
*
* @param assertion Boolean condition to test
* @param args Objects to output if assertion is false
*/
fun Console.assert(assertion: Boolean, vararg args: Any?) = unsafeCast<ExtendedConsole>().assert(assertion, *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)
* Extension function to output a stack trace to the console
*
* Maps to the browser's `console.trace()` method.
*
* [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/console/trace_static)
*/
fun Console.trace() = unsafeCast<ExtendedConsole>().trace()

View File

@@ -1,5 +1,23 @@
package dev.inmo.kslog.common
/**
* JavaScript platform implementation of the default logger
*
* Uses browser/Node.js `console` API as the logging backend, mapping KSLog levels
* to console methods:
* - [LogLevel.TRACE] → console.trace() + console.debug()
* - [LogLevel.DEBUG] → console.debug()
* - [LogLevel.VERBOSE] → console.info()
* - [LogLevel.INFO] → console.info()
* - [LogLevel.WARNING] → console.warn()
* - [LogLevel.ERROR] → console.error()
* - [LogLevel.ASSERT] → console.error()
*
* Logs can be viewed in the browser's Developer Tools console or Node.js console output.
*
* **Note**: The tag parameter is ignored in JS implementation as console methods
* don't support tagging natively.
*/
actual var KSLoggerDefaultPlatformLoggerLambda: (level: LogLevel, tag: String, message: Any, throwable: Throwable?) -> Unit = { l, _, m, e ->
val args = e ?.let {
arrayOf(m, e)