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

[SMALLFIX] Avoid new string creation in debug log #15671

Closed
wants to merge 3 commits into from

Conversation

YangchenYe323
Copy link
Contributor

@YangchenYe323 YangchenYe323 commented Jun 6, 2022

What changes are proposed in this pull request?

Check the logging level before creating a new string.

Why are the changes needed?

Fixes Alluxio/new-contributor-tasks#640

Does this PR introduce any user facing changes?

No

Replace `String.format` calls with slf4j's original formatting
ability
Comment on lines 415 to 416
LOG.debug(String.format("Open path %s with flag 0x%x for overwriting. "
+ "Alluxio deleted the old file and created a new file for writing", path, flags));
LOG.debug("Open path {} with flag {} for overwriting. "
+ "Alluxio deleted the old file and created a new file for writing", path, flags);
Copy link
Contributor

Choose a reason for hiding this comment

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

Now I see why the original author chose String.format instead of LOG.debug("{}"). The slf4j placeholder does not support formatting integers as hexadecimals. I think what you can do is surround this debug log with a check:

if (LOG.isDebugEnabled()) {
  LOG.debug(String.format(...));
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see. Submitted another patch that does this.

LOG.error(String.format("Failed to open %s: Not supported open flag 0x%x. "
LOG.error("Failed to open {}: Not supported open flag {}. "
Copy link
Contributor

Choose a reason for hiding this comment

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

These are okay since error level logging is almost always enabled, so the strings need to be created anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it. Error level logs are left untouched now.

Copy link
Contributor

@dbw9580 dbw9580 left a comment

Choose a reason for hiding this comment

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

LGTM

@YangchenYe323
Copy link
Contributor Author

alluxio-bot, merge this please

@alluxio-bot
Copy link
Contributor

Merge unsuccessful:
Insufficient permissions to trigger a PR merge. user: YangchenYe323

@dbw9580
Copy link
Contributor

dbw9580 commented Jun 8, 2022

@LuQQiu could you help merge this simple PR?

never mind, the change is not relevant any more.

@dbw9580 dbw9580 changed the title [SMALLFIX] Use slf4j's formatting ability in logs [SMALLFIX] Avoid new string creation in debug log Jun 8, 2022
@dbw9580
Copy link
Contributor

dbw9580 commented Jun 8, 2022

Closing as the code has been refactored away.

@dbw9580 dbw9580 closed this Jun 8, 2022
@YangchenYe323 YangchenYe323 deleted the debug-typo branch June 14, 2022 19:18
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.

Fix debug log in AlluxioJniFuseFileSystem
4 participants