You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
From time to time it can be useful to assert logging in tests. For example, to ensure that an operator encountering an extraneous onError goes through the default hook behavior - given that default behavior is to only log.
The trouble is that in such cases, the actual Logger is one that is statically initialized on a utility class, which is very likely to be classloaded earlier during the test run. So there's no guarantee that eg. Loggers.useCustomLogger(ignored -> new TestLogger()) would work.
Desired solution
A reactor-test way to capture log output of some tests without depending on any particular logging framework, and without forcing the whole test set to output to an in memory collection (ie logs should still go to logback for the most part).
A possible way of doing that would be to complement TestLogger in reactor-test with a Loggers factory that would by default forward to the current Loggers factory, but offer an on-demand way of diverting the logs to an assertable datastructure.
Ie. install the logger factory early (and once), but pinpoint where it capture logs in individual tests / @Before. Plus of course the possibility to reset() it to forget captured logs from one test to another.
Considered alternatives
In #2205 the LoggerUtils was introduced but it relies on the fact that logback is configured and on the test classpath. It allows to set and unset a custom Appender that additively adds to a TestLogger. This solution cannot be generalized to reactor-test, which cannot enforce a dependency to slf4j nor logback.
The text was updated successfully, but these errors were encountered:
Motivation
From time to time it can be useful to assert logging in tests. For example, to ensure that an operator encountering an extraneous
onError
goes through the default hook behavior - given that default behavior is to only log.The trouble is that in such cases, the actual
Logger
is one that is statically initialized on a utility class, which is very likely to be classloaded earlier during the test run. So there's no guarantee that eg.Loggers.useCustomLogger(ignored -> new TestLogger())
would work.Desired solution
A
reactor-test
way to capture log output of some tests without depending on any particular logging framework, and without forcing the whole test set to output to an in memory collection (ie logs should still go to logback for the most part).A possible way of doing that would be to complement
TestLogger
inreactor-test
with aLoggers
factory that would by default forward to the currentLoggers
factory, but offer an on-demand way of diverting the logs to an assertable datastructure.Ie. install the logger factory early (and once), but pinpoint where it capture logs in individual tests /
@Before
. Plus of course the possibility toreset()
it to forget captured logs from one test to another.Considered alternatives
In #2205 the
LoggerUtils
was introduced but it relies on the fact thatlogback
is configured and on the test classpath. It allows to set and unset a customAppender
that additively adds to aTestLogger
. This solution cannot be generalized toreactor-test
, which cannot enforce a dependency to slf4j nor logback.The text was updated successfully, but these errors were encountered: