quarkiverse / quarkus-logging-logback

Quarkus Logback extension
Apache License 2.0
13 stars 14 forks source link

Fix for issue 79: https://github.com/quarkiverse/quarkus-logging-logb… #113

Open tangkevkev opened 1 year ago

tangkevkev commented 1 year ago

…ack/issues/79

This solution allows the logback file to be set via system property.

As mentionned in the issue, according to the docs it should work: https://logback.qos.ch/manual/configuration.html#configFileProperty

BUT this documentation assumes that we are using logback-classic and -core with version >= 1.3.0-beta1. The mentioned DefaultJoranConfigurator exists only on these versions. We are currently using version 1.2.11

This is only a temporary fix! I think it would be nice to update the logback-classic and core versions + make the necessary adaptations.

Nevertheless it would be nice to have this approved to be used!

stuartwdouglas commented 1 year ago

I just merged an update, is this PR still nessesary?

tangkevkev commented 1 year ago

I run into runtime errors when I use the dependency build from your current main-branch (using Quarkus version 3.0.0-RC2):

java.lang.RuntimeException: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
        [error]: Build step io.quarkiverse.logging.logback.deployment.LoggingLogbackProcessor#init threw an exception: java.util.EmptyStackException
        at java.base/java.util.Stack.peek(Stack.java:102)
        at ch.qos.logback.core.model.processor.ModelInterpretationContext.peekModel(ModelInterpretationContext.java:84)
        at ch.qos.logback.core.model.processor.conditional.ElseModelHandler.handle(ElseModelHandler.java:45)
        at ch.qos.logback.core.model.processor.DefaultProcessor.secondPhaseTraverse(DefaultProcessor.java:241)
        at ch.qos.logback.core.model.processor.DefaultProcessor.secondPhaseTraverse(DefaultProcessor.java:253)
        at ch.qos.logback.core.model.processor.DefaultProcessor.secondPhaseTraverse(DefaultProcessor.java:253)
        at ch.qos.logback.core.model.processor.DefaultProcessor.secondPhaseTraverse(DefaultProcessor.java:253)
        at ch.qos.logback.core.model.processor.DefaultProcessor.traversalLoop(DefaultProcessor.java:90)
        at ch.qos.logback.core.model.processor.DefaultProcessor.process(DefaultProcessor.java:106)
        at ch.qos.logback.core.joran.GenericXMLConfigurator.processModel(GenericXMLConfigurator.java:210)
        at ch.qos.logback.core.joran.GenericXMLConfigurator.doConfigure(GenericXMLConfigurator.java:174)
        at ch.qos.logback.core.joran.GenericXMLConfigurator.doConfigure(GenericXMLConfigurator.java:126)
        at ch.qos.logback.core.joran.GenericXMLConfigurator.doConfigure(GenericXMLConfigurator.java:69)
        at io.quarkiverse.logging.logback.deployment.LoggingLogbackProcessor.init(LoggingLogbackProcessor.java:115)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at io.quarkus.deployment.ExtensionLoader$3.execute(ExtensionLoader.java:909)
        at io.quarkus.builder.BuildContext.run(BuildContext.java:282)
        at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)
        at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2513)
        at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1538)
        at java.base/java.lang.Thread.run(Thread.java:829)
        at org.jboss.threads.JBossThread.run(JBossThread.java:501)

        at io.quarkus.runner.bootstrap.AugmentActionImpl.runAugment(AugmentActionImpl.java:335)
        at io.quarkus.runner.bootstrap.AugmentActionImpl.createInitialRuntimeApplication(AugmentActionImpl.java:252)
        at io.quarkus.runner.bootstrap.AugmentActionImpl.createInitialRuntimeApplication(AugmentActionImpl.java:60)
        at io.quarkus.deployment.dev.IsolatedDevModeMain.firstStart(IsolatedDevModeMain.java:86)
        at io.quarkus.deployment.dev.IsolatedDevModeMain.accept(IsolatedDevModeMain.java:447)
        at io.quarkus.deployment.dev.IsolatedDevModeMain.accept(IsolatedDevModeMain.java:59)
        at io.quarkus.bootstrap.app.CuratedApplication.runInCl(CuratedApplication.java:149)
        at io.quarkus.bootstrap.app.CuratedApplication.runInAugmentClassLoader(CuratedApplication.java:104)
        at io.quarkus.deployment.dev.DevModeMain.start(DevModeMain.java:131)
        at io.quarkus.deployment.dev.DevModeMain.main(DevModeMain.java:62)

I also briefly looked through the changes and I think it still does not respect the docs: https://logback.qos.ch/manual/configuration.html#auto_configuration. The DefaultJoranConfigurator should be used somewhere in the code. I may be wrong, as I can't get the current version running in my project

gsmet commented 1 year ago

@tangkevkev could you provide a reproducer of your problem? The tests pass so there must be something specific to your config. Thanks!

tangkevkev commented 1 year ago

@gsmet My mistake, you were right. My configuration file was faulty! I don't encounter runtime errors anymore.

But unfortunately you still can't set the logback file via the system property.

Unfortunately, the solution I offered does not work with the updated logback versions either, because the findURLOfDefaultConfigurationFile method of the ContextInitializer does not exist anymore.