Skip to content
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

Add the ability to create anonymous loggers #71

Open
yevhenii-nadtochii opened this issue Oct 5, 2023 · 0 comments
Open

Add the ability to create anonymous loggers #71

yevhenii-nadtochii opened this issue Oct 5, 2023 · 0 comments

Comments

@yevhenii-nadtochii
Copy link
Collaborator

yevhenii-nadtochii commented Oct 5, 2023

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant