đ How do I get the java class name of a Kotlin file that contains no classes?
(I have Ktor Routing extension functions in a file and want to configure a logger with a Java class name, so that I don't have to manually code the logger name (and don't forget to update it when I rename the file.)
For example, I see that for a file RegisterRouting.kt Kotlin created a class named RegisterRoutingKt, but is there a function to get that name?
fun main() {
println(object{}.javaClass.enclosingClass)
}
Adam S
04/10/2023, 2:51 PM
kotlin-logging is a good shout đ
Adam S
04/10/2023, 2:53 PM
btw âKotlin file that contains no classesâ, the official term is âtop level functionâ or âtop level declarationâ. That might help with searches in the future :)
e
eekboom
04/10/2023, 2:56 PM
Thanks! Indeed, I already searched on SO without success and of couse, it doesn't really matter if the Kotlin files contains classes as well.