-
-
Notifications
You must be signed in to change notification settings - Fork 117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extend the way of how to create the logger #480
Comments
Thank you for reporting an issue. See the wiki for documentation and slack for questions. |
Hi, You raised here few issues and the change in the PR is quite big. |
@oshai I know that it seems lot's of changes, but actually it's not. We can separate on 3 topics:
val topLevelNamedLogger = KotlinLogging.logger("TopLevelNamedLogger")
val topLevelLambdaLogger = KotlinLogging.logger {}
class MyClass {
val classNamedLogger = KotlinLogging.logger("MyClass")
val classLambdaLogger = KotlinLogging.logger {}
val classRefLogger = KotlinLogging.logger(this)
companion object {
val companionNamedLogger = KotlinLogging.logger("MyClassCompanion")
val companionLambdaLogger = KotlinLogging.logger {}
val companionRefLogger = KotlinLogging.logger(this)
}
} Currently, for Kotlin/JS, there's a workaround involving But then I also realized that this code also will work with Kotlin/WASM and decided to add tests and change implementation as well.
|
So I suggest to separate it into 3 pull requests. About js I remember vaguely there wasn’t a good way to support both browser and node but maybe it changed or I missed something. I can try to find the old issue. |
Note: I know that's an old discussion, but just to revise it again.
Problem
Currently, the "idiomatic" way to create logger is a top-level variable.
If I'm writing a Java library, adding a variable at the top level introduces an public empty top-level class. In recent version of Kotlin we can "embed" the top-level variable using
@file:JvmName
Top level variables introduce additional top level class (if we are not using
@file:JvmName
the same as class name). It just makes the final jar bigger.Before Kotlin 2.0 each lambda functions compiled to the anonymous classes, that also makes final jar bigger, because for every logger we need a lambda. https://kotlinlang.org/docs/whatsnew20.html#generation-of-lambda-functions-using-invokedynamic
There is ongoing proposal about static namespace/static variables and current syntax does not allow to migrate (with IDEA/compiler hint) from this syntax:
to this
Suggested solution
My proposal would be to change
logger(func: () -> Unit)
tologger(ref: Any)
. Currently in all cases className derived via reflection (or even via stack trace in js), so it does not matter if it's a lambda or an object. The teams are free to chose what syntax to use then. And also the current code with lambda top-level declaration will work as well.Braking changes
Other changes
The text was updated successfully, but these errors were encountered: