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

chore: Better error message for when there is a sl4j version mismatch #32360

Merged
merged 1 commit into from
Mar 25, 2024

Conversation

johanandren
Copy link
Member

No description provided.

Comment on lines +40 to +49
private val capturingAppender =
try {
CapturingAppender.get("")
} catch {
case iae: IllegalArgumentException if iae.getMessage.contains("it was a [org.slf4j.helpers.NOPLogger]") =>
throw new RuntimeException(
"SLF could not initialize the logger, this is may be caused by accidentally having the slf4j-api dependency " +
"evicted/bumped to 2.2 by transitive dependencies while Akka only supports slf4j-api 1.7",
iae)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand it correctly, previous slf4j version would return a valid logger when we lookup for "" and then we would check if its appender is CapturingAppender, correct?

It would be better to not rely on this but find another way of lookup the declared appender.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok maybe looking up for "" was the how we could find the root logger?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I dug a little more in the code to better understand it.

When looking up for org.slf4j.Logger.ROOT_LOGGER_NAME, we get back the NOPLogger if using slf4j 2.2. Isn't that strange?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If getting slf4j-api 2.2 on path, and a logging provider that doesn't implement 2.2, it is ignored and falls back to that no-op logger, which throws the IAE higher upp in the call chain. I think this is a good place to catch that and ammend some details that may not be obvious.

This dummy lookup makes sure that failure happens early rather than intermingled with test logic where it would possibly seem like an actual test failure.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the clarification.

Copy link
Member

@octonato octonato left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@octonato octonato merged commit 94fffa0 into main Mar 25, 2024
5 checks passed
@octonato octonato deleted the wip-helpful-sl4j-mismatch-error branch March 25, 2024 21:24
@octonato octonato added this to the 2.9.3 milestone Mar 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants