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

Detect using logging before configuration #24076

Merged
merged 2 commits into from
Apr 13, 2017

Conversation

jasontedor
Copy link
Member

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.

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.
@jasontedor jasontedor requested a review from rjernst April 12, 2017 20:43
Copy link
Member

@nik9000 nik9000 left a 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) {
Copy link
Member

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.

Copy link
Member Author

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();
Copy link
Member

Choose a reason for hiding this comment

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

loggedBeforeConfigured?

Copy link
Member Author

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.

Copy link
Member Author

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");
Copy link
Member

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"?

Copy link
Member Author

Choose a reason for hiding this comment

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

I pushed 18d12a3.

@nik9000
Copy link
Member

nik9000 commented Apr 13, 2017 via email

@jasontedor jasontedor merged commit a1c2fe9 into elastic:master Apr 13, 2017
jasontedor added a commit that referenced this pull request Apr 13, 2017
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
@jasontedor jasontedor deleted the logging-before-configuring branch August 14, 2017 20:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants