quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.53k stars 2.61k forks source link

Since Quarkus 1.7.0 not able to use a log4j logging any more and getting java.lang.reflect.InvocationTargetException #11644

Open banovp opened 4 years ago

banovp commented 4 years ago

Describe the bug

Hi Quarkus Team, we have legacy app migrated and refactored in quarkus. We have some tight dependencies and special configurations for log4j, therefore we've migrated it's usage as well. Since 1.7.0 we are not able to use log4j any more and are getting the exception:

we are using log4j-core in version 2.13.3

if custom json format would be possible, than we could migrate to jboss logging.
https://github.com/quarkusio/quarkus/issues/7451

But we also need to filter the max length of the log lines (because of aws fargate v. 1.4.0, which have issues with the length), which is actually with the logging mechanism of quarkus not possible.

2020-08-26 14:54:07,896 ERROR [io.qua.run.boo.StartupActionImpl] (Quarkus Main Thread) Error running Quarkus: java.lang.reflect.InvocationTargetException
    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.runner.bootstrap.StartupActionImpl$3.run(StartupActionImpl.java:145)
    at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.ExceptionInInitializerError
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
    at java.base/java.lang.Class.newInstance(Class.java:584)
    at io.quarkus.runtime.Quarkus.run(Quarkus.java:60)
    at io.quarkus.runtime.Quarkus.run(Quarkus.java:38)
    at io.quarkus.runtime.Quarkus.run(Quarkus.java:106)
    at io.quarkus.runner.GeneratedMain.main(GeneratedMain.zig:29)
    ... 6 more
Caused by: java.lang.RuntimeException: Failed to start quarkus
    at io.quarkus.runner.ApplicationImpl.<clinit>(ApplicationImpl.zig:288)
    ... 15 more
Caused by: java.lang.RuntimeException: Failed to initialize Arc
    at io.quarkus.arc.Arc.initialize(Arc.java:26)
    at io.quarkus.arc.runtime.ArcRecorder.getContainer(ArcRecorder.java:35)
    at io.quarkus.deployment.steps.ArcProcessor$generateResources1649676420.deploy_0(ArcProcessor$generateResources1649676420.zig:76)
    at io.quarkus.deployment.steps.ArcProcessor$generateResources1649676420.deploy(ArcProcessor$generateResources1649676420.zig:40)
    at io.quarkus.runner.ApplicationImpl.<clinit>(ApplicationImpl.zig:224)
    ... 15 more
Caused by: java.lang.IllegalAccessError: failed to access class org.apache.logging.log4j.util.StackLocator$FqcnCallerLocator from class org.apache.logging.log4j.util.StackLocator (org.apache.logging.log4j.util.StackLocator$FqcnCallerLocator is in unnamed module of loader 'app'; org.apache.logging.log4j.util.StackLocator is in unnamed module of loader io.quarkus.bootstrap.classloading.QuarkusClassLoader @289fdb08)
    at org.apache.logging.log4j.util.StackLocator.<clinit>(StackLocator.java:37)
    at org.apache.logging.log4j.util.StackLocatorUtil.<clinit>(StackLocatorUtil.java:33)
    at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.getContext(ClassLoaderContextSelector.java:133)
    at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:228)
    at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)
    at org.apache.logging.log4j.LogManager.getContext(LogManager.java:174)
    at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:669)
    at com.example.cd.logging.Logger.<clinit>(Logger.java:36)
    at com.example.v1.control.TestService.<clinit>(TestService.java:10)
    at java.base/java.lang.Class.forName0(Native Method)
    at java.base/java.lang.Class.forName(Class.java:398)
    at com.example.v1.control.TestService_Bean.<init>(TestService_Bean.zig:73)
    at io.quarkus.arc.setup.Default_ComponentsProvider.addBeans1(Default_ComponentsProvider.zig:122)
    at io.quarkus.arc.setup.Default_ComponentsProvider.getComponents(Default_ComponentsProvider.zig:38)
    at io.quarkus.arc.impl.ArcContainerImpl.<init>(ArcContainerImpl.java:109)
    at io.quarkus.arc.Arc.initialize(Arc.java:20)
    ... 19 more

Expected behavior log4j should be usable also instead of quarkus logging

Actual behavior only quarkus logging is possible

To Reproduce Steps to reproduce the behavior:

  1. use log4j logger since quakrus 1.7.0

Configuration

n.a.

Screenshots n.a.

Environment (please complete the following information): n.a. quarkus since 1.7.0

Additional context n.a.

yuriyz commented 3 years ago

@banovp here is how we solved it on our side, maybe it will help in your case too https://github.com/GluuFederation/oxauth-config/issues/165#issuecomment-691041339

rolandhaas commented 3 years ago

I fight the same issue. Do we have an update on this? Until a proper fix we will remain on version 1.6.x of quarkus (unfortunately the provided workourd doesn't seem to be working on our side)

galderz commented 3 years ago

@rolandhaas I think it's something specific to log4j itself (independent of Quarkus), see this stackoverflow question. Best exclude log4j dependency and use Quarkus' blessed log4j dependency.