KAFKA-17168: Remove the logPrefix to print the thread name#16657
KAFKA-17168: Remove the logPrefix to print the thread name#16657chia7712 merged 3 commits intoapache:trunkfrom
Conversation
User can configure the log4j conversion-pattern to print the thread name if required.
|
|
||
| public class RemoteStorageThreadPool extends ThreadPoolExecutor { | ||
| private final Logger logger; | ||
| private final Logger logger = LoggerFactory.getLogger(RemoteStorageThreadPool.class); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
@kamalcph could you please fix the build error? it seems we have to rename "logger" to "LOGGER" |
|
Test failures are unrelated. |
…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>
Reviewers: Kuan-Po (Cooper) Tseng <brandboat@gmail.com>, Satish Duggana <satishd@apache.org>, Chia-Ping Tsai <chia7712@gmail.com>
…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>
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)