-
-
Notifications
You must be signed in to change notification settings - Fork 123
Issue #484 - Optimize the KLoggerNameResolver for jvm #485
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
Conversation
…don't need to search indexOf multiple times
I am not sure what is the optimization here? |
@oshai it's unnecessary to search the same delimiter twice
|
@oshai also please note, that there is a problem with a tests that're not covering |
got it. I am not sure wdym by tests not covering func. Anyway, it will be nice if you'll add unit test to the changed class. |
@oshai I'll update the tests, but they will rely on current behavior. For example, tests expected to support inner classes Arguments.of("io.github.oshai.kotlinlogging.internal.Foo\$Bar", Foo.Bar::class.java) But currently Inner classes are not supported already, therefore it may seems that my changes break behavior, but actually not, this behavior was already changed. You can try this with the latest library version class Base {
class Inner {
private companion object {
private val logger = KotlinLogging.logger { }
}
init {
logger.info { "Hello" }
}
}
}
fun main() {
Base.Inner()
}
Please, see the comment here: #484 (comment) |
@oshai please have a look |
return name(func::class) | ||
} | ||
|
||
internal fun name(clazz: KClass<*>): String { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this method should be private
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@oshai historically this method was used in the tests, therefore it's not possible to make it private without rewriting tests structure. https://github.com/oshai/kotlin-logging/blob/master/src/javaMain/kotlin/io/github/oshai/kotlinlogging/internal/KLoggerNameResolver.kt#L21
I would prefer to keep it internal for now and if the changes from #481 will be accepted, then signature of the method will be changed from
internal actual fun name(func: () -> Unit): String
to
internal actual fun name(ref: Any): String {
and then we can update the tests to use instances of the classes, rather then KClass
ok. checks are now failing - I think on code formatting. |
Applied formatting, I'm sorry, completely forgot about it |
Also I think it's worth to mention somewhere in the documentation that loggers in the inner classes always will have the name of the parent(base) class. Example from here #485 (comment) Or create another issue if it supposed to be fixed |
Created issue about logger name for inner class #495 |
Thanks for the PR! |
closes #484