Reputation: 1201
tl;dr: The docs don't mention how to do that and there also don't seem to be config values to support that (see All configuration options). Is there a way to have a custom log appender somehow?
For testing applications I like to evaluate log messages. For that to work you need implement your own log appender which stores the log messages in some data structure, then configure your logging backend to use this appender additionally if the application is run in the test context. For Logback it's just a class which extends AppenderBase<ILoggingEvent>
and adding that to logback-test.xml
as additional appender.
Since Logback is not supported by Quarkus, I tried to create a custom log appender with Log4j2
but had to find out that this also requires to add the dependency log4j-core
because log4j2-jboss-logmanager
does not contain the required classes and the docs say "Do not include any Log4j dependencies" (see here)
Maybe I have a general misunderstanding here? Thanks for any suggestion!
Upvotes: 1
Views: 1934
Reputation: 1201
So this doesn't seem to be supported out of the box (see here). You have to write your own Quarkus extension as this GitHub Anon points out. And he actually did implement such a thing (see here). The problem with extensions is they not that easy to implement (see here) and they have to maintained.
Since the main point of the original question is to use logs just for testing, it's probably easier to have a workaround with the existing log handlers:
%test
context, write your logs into the file and parse it to make assertions.System.out
by default (see here & here) It should also be possible to overwrite it (it's just a PrintStream
) with your own OutputStream
which you can turn into a string after the tests ran through. But that's probably a bad solution since you won't have console output during the test run and might create other problems.Upvotes: 1