-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
JBoss.Logging in junit tests #7696
Comments
I'm using a temporary work-around of placing slf4j-log4j12 as a test dependency placed before other dependencies. |
Agree, the way logging is currently implemented is a pain. It would be good to have some flexibility here. |
A trick is to provide a different LoggerProvider using org.jboss.logging.provider system property for unit tests. In LoggerProviders, this is the first thing that is done for getting a LoggerProvider. |
We're using slf4j api in all our code. Quarkus puts an impl (from jboss) on the classpath. When i run a normal (non quarkus) junit tests from my IDE, i have no clue how to configure logging. It is not explained anywhere. What i get: "LogManager error of type WRITE_FAILURE: The delayed handler's queue was overrun and log record(s) were lost. Did you forget to configure logging?" What to do?
|
Another trick is to completely remove
Then you can add your logging library as test scope dependency (e.g. slf4j):
And then, at the end, put a simple log4j.properties in test/resources directory. It seems to work both on @QuarkusTest and normal junit test. |
Nice, although it looks like Eclipse doesn't honour that. Good on Maven cli though. |
I can confirm that having this log4j2 slf4j binding as first dependency (test scoped) in the pom.xml org.apache.logging.log4j log4j-slf4j-impl 2.14.1 test ... all other dependencies belowworks for running plain old non-quarkus junit tests from eclipse: eclipse respects that order, slf4j complains about 2 impl's but then carries on with this log4j2 impl, who's config i control via JRE default VM argument -Dlog4j.configurationFile=file:///home/dcailliau/log4j2.properties I think this is worth mentioning in the quarkus docs. |
I invite everyone to try out 2.7.0.CR1 which was released today! Update: 2.7.0.Final is now generally available. It comes with #22920 that added a global JUnit callback that tries to set up "basic" logging before any JUnit test class, which includes non-Quarkus JUnit-based tests. If (and only if!) you have a custom Finally, a note on "basic": This setup will include most of the logging config but nothing contributed by extensions. If you are missing something very important, please let me know! Feedback is very much appreciated! |
Small update: As of 2.7.1.Final, |
With Quarkus 2.7.1 the configuration of logging in plain unit tests is now supported. See quarkusio/quarkus#7696. Modules have been updated to make an explicit decision regarding the logging framework to use for running unit tests. In particular, modules can now also successfully use the JBoss LogManager and its SLF4J bridge introduced by Quarkus dependencies. Signed-off-by: Kai Hudalla <[email protected]>
With Quarkus 2.7.1 the configuration of logging in plain unit tests is now supported. See quarkusio/quarkus#7696. Modules have been updated to make an explicit decision regarding the logging framework to use for running unit tests. In particular, modules can now also successfully use the JBoss LogManager and its SLF4J bridge introduced by Quarkus dependencies. Signed-off-by: Kai Hudalla <[email protected]>
2.7.2 has further improved the situation, so I'll close this issue. Please open a new issue in case you thinks something is not right or missing. |
@famod The above issue text mentions a scenario where logback is used, with a As for the |
@calohmn yeah, |
Just for the future reference, the initial delay is caused by surefire: |
Yeah, I strongly recommend using surefire 3.0.0-M7. |
as recommended by quarkusio/quarkus#7696 (comment) Signed-off-by: Kai Hudalla <[email protected]>
In case someone finds this in 2023+ and logging does not work with Slf4j in tests, these are the only changes that needed to be done
|
Describe the bug
In case I would like to use JUnit for the purpose it was conceived (testing methods within small confined test scenarios without starting quarkus) and would like to use SLF4J for logging, then JBoss Logging gets into the way. It is virtually impossible to configure jboss logging by dropping some file on classpath like logback-test.xml or whatnot.
Additionally the logging is delayed at startup by some sort of buffering. Therefore you will only see the result of the log later, so your observation about some parts of the test is slow is wrong.
Update: the delay is caused by surefire!
Expected behavior
Adding logback-classic into the classpath would work fine or alternative there should be some canonical way of configuring the logging for unit tests without paying the 4-5 sec penalty to start the quarkus instance.
Actual behavior
Need to exclude bindings from every extension:
io.quarkus
quarkus-hibernate-orm
slf4j-jboss-logging
org.jboss.slf4j
Workaround
By adding a dependency exclude to surefire, the logmanager can be removed from the classpath, then any provider can take its place:
To Reproduce
Steps to reproduce the behavior:
Environment (please complete the following information):
Output of
uname -a
orver
: Linux conegliano 4.15.0-76-generic Opentracing take2 (OKAY TO MERGE) #86-Ubuntu SMP Fri Jan 17 17:24:28 UTC 2020 x86_64 x86_64 x86_64 GNU/LinuxOutput of
java -version
:openjdk version "1.8.0_242"
OpenJDK Runtime Environment (Zulu 8.44.0.11-CA-linux64) (build 1.8.0_242-b20)
OpenJDK 64-Bit Server VM (Zulu 8.44.0.11-CA-linux64) (build 25.242-b20, mixed mode)
GraalVM version (if different from Java):
openjdk version "1.8.0_242"
OpenJDK Runtime Environment (build 1.8.0_242-b06)
OpenJDK 64-Bit GraalVM CE 19.3.1 (build 25.242-b06-jvmci-19.3-b07, mixed mode)
Quarkus version or git rev: 1.2.0
Build tool (ie. output of
mvnw --version
orgradlew --version
):Apache Maven 3.6.0
Additional context
(Add any other context about the problem here.)
The text was updated successfully, but these errors were encountered: