Repository navigation
How to manually set the logger name in Kotlin/Js? #580
Description
I have read a few issues here (almost all opened and closed which mention Kotlin JS: https://github.com/oshai/kotlin-logging/issues?q=sort%3Aupdated-desc%20is%3Aissue%20kotlin%20js), and almost nothing works for me. I also looked at - #500.
I am working on an Obsidian plugin, which is an electron application (so i would say it's Node).
My setup:
// kotlin version: 2.2.20
kotlin {
js {
outputModuleName = "shared"
nodejs {
}
binaries.executable()
generateTypeScriptDefinitions()
compilerOptions {
target = "es2015"
moduleKind = org.jetbrains.kotlin.gradle.dsl.JsModuleKind.MODULE_COMMONJS
}
}
compilerOptions {
apiVersion = KotlinVersion.KOTLIN_2_2
languageVersion = KotlinVersion.KOTLIN_2_2
}
sourceSets {
commonMain {
dependencies {
api(kotlin("stdlib"))
implementation(libs.kotlinx.coroutines.core)
implementation ("io.github.oshai:kotlin-logging:7.0.13")
}
}
jsMain.dependencies {
api(kotlin("stdlib-js"))
api(project(":obsidian-api"))
}
I have tried multiple combinations of creating my logger (top level variable, object, companion object) and this is my current state:
class log {
// val log = KotlinLogging.logger {}
// val log = KotlinLogging.logger("ll")
val log by KotlinLogging.logger()
}And usage in another function outside of a class:
fun cycleViewStateForwardCallback(leaf: WorkspaceLeaf) {
[...]
KotlinLoggingConfiguration.logLevel = Level.TRACE
log().log.info { "log info" }Here are my outputs and errors:
val log = KotlinLogging.logger {}- this is the only way in which i can get any output
INFO: [ at new log (plugin:tbp-toolbox:4028:24)] log info
val log = KotlinLogging.logger("ll")- error
Plugin failure: tbp-toolbox TypeError: context.m9 is not a function
at SupervisorJobImpl.plus [as n9] (plugin:tbp-toolbox:1694:21)
at new TbpToolboxPlugin (plugin:tbp-toolbox:3637:52)
at new default_0 (plugin:tbp-toolbox:3655:3)
(longer stacktrace, doesn't look interesting to me)
val log by KotlinLogging.logger()- error
lugin failure: tbp-toolbox TypeError: context.p9 is not a function
at SupervisorJobImpl.plus [as q9] (plugin:tbp-toolbox:1702:21)
at new TbpToolboxPlugin (plugin:tbp-toolbox:3669:52)
at new default_0 (plugin:tbp-toolbox:3687:3)
(longer stacktrace, doesn't look interesting to me)
Looking through all those issues, I believe i tried all ways to create my logger and none of them give me the proper log name that i want.
My desired output would be:
INFO: [ll] log info
maybe customized somehow with the current time (23:51:66.01214567), but that's just if i want to get fancy.
How can i set my desired log name?
If there is any output you may need, i can give that too. My plugin is exported in a single main.js file, so I can provide that too.
Activity
oshai commentedon Nov 9, 2025
I don't know why option #2 doesn't work for you but it's the most straight forward way to define logger name. Looks like somehow the common code is not linked so you have this failure (the definition is in here).
TheBestPessimist commentedon Nov 9, 2025
@oshai do you have any suggestions for things i could try?
TheBestPessimist commentedon Nov 9, 2025
If it helps, my repo is here: https://github.com/TheBestPessimist/tbp-toolbox-obsidian
Also, maybe it helps (or not?) but i'm running my logging code from inside a manually created coroutine scope (and i'm a noob at coroutines):
oshai commentedon Jan 2, 2026
Have you find the cause or still need assistance?
TheBestPessimist commentedon Jan 3, 2026
Thanks for asking @oshai. I have stopped trying to understand what's going on. If i needed a lot, i added console.logs and that's it. Not nice, but it works for now