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

Explore a utility LoggerFactory to allow late binding of Loggers in tests #2269

Closed
simonbasle opened this issue Jul 15, 2020 · 0 comments
Closed
Assignees
Labels
area/reactor-test This belongs to the reactor-test module type/enhancement A general enhancement
Milestone

Comments

@simonbasle
Copy link
Member

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 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.

@simonbasle simonbasle added type/enhancement A general enhancement status/need-decision This needs a decision from the team area/reactor-test This belongs to the reactor-test module status/need-design This needs more in depth design work labels Jul 15, 2020
@simonbasle simonbasle added this to the Backlog milestone Jul 15, 2020
@simonbasle simonbasle removed status/need-decision This needs a decision from the team status/need-design This needs more in depth design work labels Nov 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/reactor-test This belongs to the reactor-test module type/enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants