-
Notifications
You must be signed in to change notification settings - Fork 25k
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
Detect using logging before configuration #24076
Detect using logging before configuration #24076
Conversation
It can easily happen that we touch a logger before logging is configured due to chains of static intializers and other such scenarios. This commit adds detection for this mechanism that will fail startup if we touch a logger before logging is configured. This is a bug that will cause builds to fail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to me. I left some recommendations around naming things so it'd be easier for someone skimming the classes to know what was happening.
|
||
public class LogConfigurator { | ||
|
||
private static final AtomicBoolean error = new AtomicBoolean(); | ||
|
||
private static final StatusListener LISTENER = new StatusConsoleListener(Level.ERROR) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe name it UNCONFIGURED_LOG_CATCHER
or something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pushed 18d12a3.
|
||
public class LogConfigurator { | ||
|
||
private static final AtomicBoolean error = new AtomicBoolean(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
loggedBeforeConfigured?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The most likely error that is logged here is that we touched a logger before it's configured, but any error message from the status logger is going to trip this check so I'd rather keep the name general. I'm happy to add a comment that explains this though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pushed 18d12a3.
private static void checkErrorListener() { | ||
assert errorListenerIsRegistered() : "expected error listener to be registered"; | ||
if (error.get()) { | ||
throw new IllegalStateException("status logger logged an error before logging was configured"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe change the message to something like "used logging before it was configured"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pushed 18d12a3.
Makes sense to me!
…On Wed, Apr 12, 2017, 9:02 PM Jason Tedor ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In
core/src/main/java/org/elasticsearch/common/logging/LogConfigurator.java
<#24076 (comment)>
:
>
public class LogConfigurator {
+ private static final AtomicBoolean error = new AtomicBoolean();
The most likely error that is logged here is that we touched a logger
before it's configured, but any error message from the status logger is
going to trip this check so I'd rather keep the name general. I'm happy to
add a comment that explains this though.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#24076 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AANLohoFiG33UibC9nu0JhLf5h9gkYLxks5rvXQJgaJpZM4M78km>
.
|
It can easily happen that we touch a logger before logging is configured due to chains of static intializers and other such scenarios. This commit adds detection for this mechanism that will fail startup if we touch a logger before logging is configured. This is a bug that will cause builds to fail. Relates #24076
It can easily happen that we touch a logger before logging is configured due to chains of static intializers and other such scenarios. This commit adds detection for this mechanism that will fail startup if we touch a logger before logging is configured. This is a bug that will cause builds to fail.