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

java.lang.ClassNotFoundException when using console appender #81

Open
peterhuba opened this issue Aug 11, 2022 · 1 comment
Open

java.lang.ClassNotFoundException when using console appender #81

peterhuba opened this issue Aug 11, 2022 · 1 comment

Comments

@peterhuba
Copy link

peterhuba commented Aug 11, 2022

Hello,

There apparently a class loading issue when using a Logback console appender.
Steps to reproduce:

  1. clone quarkiverse/quarkus-logging-logback
  2. in quarkus-logging-logback/integration-tests/pom.xml change quarkus-logging-logback version to 0.13.0
  3. replace the quarkus-logging-logback/integration-tests/src/main/resources/logback.xml file's contents with the following:
<configuration debug="true">

    <appender name="FILE" class="ch.qos.logback.core.FileAppender">
        <file>target/tests.log</file>
        <append>false</append>
        <encoder>
            <pattern>LOGBACK- %-5level %msg %n</pattern>
        </encoder>
    </appender>

    <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <pattern>%d{HH:mm:ss.SSS} %gray(\(%t\)) %green(%-5level) %highlight([%logger{36}]) %msg%n</pattern>
        </encoder>
    </appender>

    <root level="INFO">
        <appender-ref ref="FILE" />
        <appender-ref ref="CONSOLE" />
    </root>
</configuration>
  1. run mvn clean verify -Dnative in directory quarkus-logging-logback/integration-tests
  2. observe the output:
...
...
06:36:26,912 |-ERROR in ch.qos.logback.core.pattern.parser.Compiler@53307460 - [msg] is not a valid conversion word
06:36:26,912 |-ERROR in ch.qos.logback.core.pattern.parser.Compiler@53307460 - Failed to instantiate converter class [ch.qos.logback.classic.pattern.LineSeparatorConverter] for keyword [n] ch.qos.logback.core.util.DynamicClassLoadingException: Failed to instantiate type ch.qos.logback.classic.pattern.LineSeparatorConverter
        at ch.qos.logback.core.util.DynamicClassLoadingException: Failed to instantiate type ch.qos.logback.classic.pattern.LineSeparatorConverter
        at      at ch.qos.logback.core.util.OptionHelper.instantiateByClassNameAndParameter(OptionHelper.java:68)
        at      at ch.qos.logback.core.util.OptionHelper.instantiateByClassName(OptionHelper.java:44)
        at      at ch.qos.logback.core.util.OptionHelper.instantiateByClassName(OptionHelper.java:33)
        at      at ch.qos.logback.core.pattern.parser.Compiler.createConverter(Compiler.java:104)
        at      at ch.qos.logback.core.pattern.parser.Compiler.compile(Compiler.java:63)
        at      at ch.qos.logback.core.pattern.parser.Parser.compile(Parser.java:87)
        at      at ch.qos.logback.core.pattern.PatternLayoutBase.start(PatternLayoutBase.java:84)
        at      at ch.qos.logback.classic.encoder.PatternLayoutEncoder.start(PatternLayoutEncoder.java:28)
        at      at ch.qos.logback.classic.encoder.PatternLayoutEncoder$$delayed.doQuarkusDelayedStart(Unknown Source)
        at      at io.quarkiverse.logback.runtime.LogbackRecorder.createHandler(LogbackRecorder.java:130)
        at      at io.quarkus.deployment.steps.LoggingLogbackProcessor$handler1311068917.deploy_0(Unknown Source)
        at      at io.quarkus.deployment.steps.LoggingLogbackProcessor$handler1311068917.deploy(Unknown Source)
        at      at io.quarkus.runner.ApplicationImpl.doStart(Unknown Source)
        at      at io.quarkus.runtime.Application.start(Application.java:101)
        at      at io.quarkus.runtime.ApplicationLifecycleManager.run(ApplicationLifecycleManager.java:103)
        at      at io.quarkus.runtime.Quarkus.run(Quarkus.java:67)
        at      at io.quarkus.runtime.Quarkus.run(Quarkus.java:41)
        at      at io.quarkus.runtime.Quarkus.run(Quarkus.java:120)
        at      at io.quarkus.runner.GeneratedMain.main(Unknown Source)
Caused by: java.lang.ClassNotFoundException: ch.qos.logback.classic.pattern.LineSeparatorConverter
        at      at jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:52)
        at      at jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
        at      at java.lang.ClassLoader.loadClass(ClassLoader.java:133)
        at      at ch.qos.logback.core.util.OptionHelper.instantiateByClassNameAndParameter(OptionHelper.java:55)
        at      ... 18 common frames omitted
06:36:26,913 |-ERROR in ch.qos.logback.core.pattern.parser.Compiler@53307460 - [n] is not a valid conversion word
%PARSER_ERROR[d] %PARSER_ERROR[gray] %PARSER_ERROR[green] %PARSER_ERROR[highlight] %PARSER_ERROR[msg]%PARSER_ERROR[n]%PARSER_ERROR[d] %PARSER_ERROR[gray] %PARSER_ERROR[green] %PARSER_ERROR[highlight] %PARSER_ERROR[msg]%PARSER_ERROR[n]%PARSER_ERROR[d] %PARSER_ERROR[gray] %PARSER_ERROR[green] %PARSER_ERROR[highlight] %PARSER_ERROR[msg]%PARSER_ERROR[n][INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.981 s - in io.quarkiverse.logging.logback.it.NativeLoggingLogbackResourceIT
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO]
[INFO] --- maven-failsafe-plugin:2.22.2:verify (default) @ quarkus-logging-logback-integration-tests ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  01:57 min
[INFO] Finished at: 2022-08-11T09:36:28+03:00
[INFO] ------------------------------------------------------------------------

Do you have any suggestion what could be done about this?
Thanks!

@peterhuba
Copy link
Author

Adding to pom.xml logback-core and logback-classic then registering for reflection the problematic classes does work as a workaround

@RegisterForReflection(targets = {
        LineSeparatorConverter.class,
        HighlightingCompositeConverter.class,
        GrayCompositeConverter.class,
        GreenCompositeConverter.class,
        ThreadConverter.class,
        LoggerConverter.class,
        LevelConverter.class,
        DateConverter.class,
        MessageConverter.class
})

but wondering if this could be assured within the extension.

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