-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Now, it is impossible to create a logger from main method:
fun main() {
val logger = LoggingFactory.forEnclosingClass()
logger.atInfo().log { "..." }
}The snippet above fails with the following exception:
Exception in thread "main" java.lang.UnsupportedOperationException: Packages and file facades are not yet supported in Kotlin reflection. Meanwhile please use Java reflection to inspect this class: class logging.test.AppKt
Full stack trace
Exception in thread "main" java.lang.UnsupportedOperationException: Packages and file facades are not yet supported in Kotlin reflection. Meanwhile please use Java reflection to inspect this class: class logging.test.AppKt
at kotlin.reflect.jvm.internal.KClassImpl.reportUnresolvedClass(KClassImpl.kt:310)
at kotlin.reflect.jvm.internal.KClassImpl.access$reportUnresolvedClass(KClassImpl.kt:44)
at kotlin.reflect.jvm.internal.KClassImpl$Data$descriptor$2.invoke(KClassImpl.kt:56)
at kotlin.reflect.jvm.internal.KClassImpl$Data$descriptor$2.invoke(KClassImpl.kt:48)
at kotlin.reflect.jvm.internal.ReflectProperties$LazySoftVal.invoke(ReflectProperties.java:93)
at kotlin.reflect.jvm.internal.ReflectProperties$Val.getValue(ReflectProperties.java:32)
at kotlin.reflect.jvm.internal.KClassImpl$Data.getDescriptor(KClassImpl.kt:48)
at kotlin.reflect.jvm.internal.KClassImpl$Data$annotations$2.invoke(KClassImpl.kt:59)
at kotlin.reflect.jvm.internal.KClassImpl$Data$annotations$2.invoke(KClassImpl.kt:59)
at kotlin.reflect.jvm.internal.ReflectProperties$LazySoftVal.invoke(ReflectProperties.java:93)
at kotlin.reflect.jvm.internal.ReflectProperties$Val.getValue(ReflectProperties.java:32)
at kotlin.reflect.jvm.internal.KClassImpl$Data.getAnnotations(KClassImpl.kt:59)
at kotlin.reflect.jvm.internal.KClassImpl.getAnnotations(KClassImpl.kt:184)
at io.spine.logging.LoggingDomainClassValue.computeValue(LoggingDomainClassValue.kt:104)
at io.spine.logging.LoggingDomainClassValue.computeValue(LoggingDomainClassValue.kt:46)
at java.base/java.lang.ClassValue.getFromHashMap(ClassValue.java:228)
at java.base/java.lang.ClassValue.getFromBackup(ClassValue.java:210)
at java.base/java.lang.ClassValue.get(ClassValue.java:116)
at io.spine.logging.LoggingDomainClassValue.get$logging(LoggingDomainClassValue.kt:50)
at io.spine.logging.LoggingFactory.loggingDomainOf(LoggingFactory.kt:53)
at io.spine.logging.Logger.at(Logger.kt:58)
at io.spine.logging.Logger.atInfo(Logger.kt:100)
at logging.test.AppKt.main(App.kt:16)
at logging.test.AppKt.main(App.kt)
Although, it doesn't seem very useful in production code, such usage is important. main is often used to create code snippets, quickly try out a new library (e.g., logging library!), test something, etc.
So, I suggest either adding of LoggingFactory.anonymousLogger() or allow LoggingFactory.forEnclosingClass() create loggers for ephemeral Kotlin classes (in the example above, it is AppKt class).
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels