Skip to content

KAFKA-17168: Remove the logPrefix to print the thread name#16657

Merged
chia7712 merged 3 commits intoapache:trunkfrom
kamalcph:KAFKA-17168
Jul 24, 2024
Merged

KAFKA-17168: Remove the logPrefix to print the thread name#16657
chia7712 merged 3 commits intoapache:trunkfrom
kamalcph:KAFKA-17168

Conversation

@kamalcph
Copy link
Copy Markdown
Contributor

@kamalcph kamalcph commented Jul 22, 2024

Users can configure the log4j conversion-pattern to print the thread name if required. It is a followup of the comment.

Committer Checklist (excluded from commit message)

  • Verify design and implementation
  • Verify test coverage and CI build status
  • Verify documentation (including upgrade notes)

User can configure the log4j conversion-pattern to print the thread name if required.
@kamalcph kamalcph changed the title KAFKA-17168: Remove the logPrefix to print the thread name. KAFKA-17168: Remove the logPrefix to print the thread name Jul 22, 2024
Copy link
Copy Markdown
Member

@chia7712 chia7712 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Copy Markdown
Member

@brandboat brandboat left a comment

Choose a reason for hiding this comment

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

LGTM !

Copy link
Copy Markdown
Member

@satishd satishd left a comment

Choose a reason for hiding this comment

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

Thanks @kamalcph for following up on this PR, left a comment.


public class RemoteStorageThreadPool extends ThreadPoolExecutor {
private final Logger logger;
private final Logger logger = LoggerFactory.getLogger(RemoteStorageThreadPool.class);
Copy link
Copy Markdown
Member

@satishd satishd Jul 22, 2024

Choose a reason for hiding this comment

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

Can you make this as static to avoid creating multiple logger instances as we do not need any context for each instance? I understand that we create only a single instance for now but it is good to make this logger static even if we create multiple instances in future.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I understand that we create only a single instance for now but it is good to make this logger static even if we create multiple instances in future.

that is a good point. The default provider reload4j maintain the logger instance for each class name, so the instance should be same even though we don't use static. However, it seems slf4j docs does not describe such behavior so we can't assume other providers are same

for another, we should apply the static to code base. 1) unify the code style and 2) avoid multiple logger instances in the future.

@chia7712
Copy link
Copy Markdown
Member

@kamalcph could you please fix the build error? it seems we have to rename "logger" to "LOGGER"

Copy link
Copy Markdown
Member

@satishd satishd left a comment

Choose a reason for hiding this comment

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

Thanks @kamalcph for addressing the review comments. LGTM.

@kamalcph
Copy link
Copy Markdown
Contributor Author

Test failures are unrelated.

@chia7712 chia7712 merged commit 539f466 into apache:trunk Jul 24, 2024
@kamalcph kamalcph deleted the KAFKA-17168 branch July 26, 2024 13:27
chia7712 pushed a commit that referenced this pull request Jul 30, 2024
…ances (#16680)

As discussed in #16657 (comment) , we should make logger as static to avoid creating multiple logger instances.
I use the regex private.*Logger.*LoggerFactory to search and check all the results if certain logs need to be static.

There are some exceptions that loggers don't need to be static:
1) The logger in the inner class. Since java8 doesn't support static field in the inner class.
        https://github.com/apache/kafka/blob/trunk/clients/src/test/java/org/apache/kafka/clients/consumer/internals/FetchRequestManagerTest.java#L3676

2) Custom loggers for each instance (non-static + non-final). In this case, multiple logger instances is actually really needed.
        https://github.com/apache/kafka/blob/trunk/storage/src/test/java/org/apache/kafka/server/log/remote/storage/LocalTieredStorage.java#L166

3) The logger is initialized in constructor by LogContext. Many non-static but with final modifier loggers are in this category, that's why I use .*LoggerFactory to only check the loggers that are assigned initial value when declaration.
    
4) protected final Logger log = Logger.getLogger(getClass())
    This is for subclass can do logging with subclass name instead of superclass name.
    But in this case, if the log access modifier is private, the purpose cannot be achieved since subclass cannot access the log defined in superclass. So if access modifier is private, we can replace getClass() with <className>.class

Reviewers: Chia-Ping Tsai <chia7712@gmail.com>
abhi-ksolves pushed a commit to ksolves/kafka that referenced this pull request Jul 31, 2024
Reviewers: Kuan-Po (Cooper) Tseng <brandboat@gmail.com>, Satish Duggana <satishd@apache.org>, Chia-Ping Tsai <chia7712@gmail.com>
abhi-ksolves pushed a commit to ksolves/kafka that referenced this pull request Jul 31, 2024
…ances (apache#16680)

As discussed in apache#16657 (comment) , we should make logger as static to avoid creating multiple logger instances.
I use the regex private.*Logger.*LoggerFactory to search and check all the results if certain logs need to be static.

There are some exceptions that loggers don't need to be static:
1) The logger in the inner class. Since java8 doesn't support static field in the inner class.
        https://github.com/apache/kafka/blob/trunk/clients/src/test/java/org/apache/kafka/clients/consumer/internals/FetchRequestManagerTest.java#L3676

2) Custom loggers for each instance (non-static + non-final). In this case, multiple logger instances is actually really needed.
        https://github.com/apache/kafka/blob/trunk/storage/src/test/java/org/apache/kafka/server/log/remote/storage/LocalTieredStorage.java#L166

3) The logger is initialized in constructor by LogContext. Many non-static but with final modifier loggers are in this category, that's why I use .*LoggerFactory to only check the loggers that are assigned initial value when declaration.
    
4) protected final Logger log = Logger.getLogger(getClass())
    This is for subclass can do logging with subclass name instead of superclass name.
    But in this case, if the log access modifier is private, the purpose cannot be achieved since subclass cannot access the log defined in superclass. So if access modifier is private, we can replace getClass() with <className>.class

Reviewers: Chia-Ping Tsai <chia7712@gmail.com>
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.

4 participants