Details
-
Improvement
-
Resolution: Duplicate
-
Minor
-
None
-
None
Description
Working with logger is essential for troubleshooting but sometime there is way too much debug logs. Sometime they are too verbose but still needed.
I came across a issue with disk spaces and the logs were top blame.
I want to propose a simple feature to the logger.
Let say I have a really fast and verbose thread algorithm.
2022-06-10 14:27:23:123 -0400 [normal] DEBUG org.slf4j.impl.App - Calling internal process 2022-06-10 14:27:23:123 -0400 [normal] DEBUG org.slf4j.impl.App - Clean up list from empty or null string 2022-06-10 14:27:23:123 -0400 [normal] DEBUG org.slf4j.impl.App - Removing : "" 2022-06-10 14:27:23:123 -0400 [normal] DEBUG org.slf4j.impl.App - Removing : "null" <...> 2022-06-10 14:27:23:123 -0400 [normal] INFO org.slf4j.impl.App - Listing entries 2022-06-10 14:27:23:124 -0400 [compact] DEBUG org.slf4j.impl.App - Return to Normal log
I propose to include a flag that will keep the logging and avoid duplicated the pattern.
I want to:
Use ThreadLocal to avoid impacting all the other logs.
Enable programmatically to be specific for known verbose path only
Keep the initial pattern of the first log call.
Enable it only for debug level, other level will continue to be log with the pattern.
Closable to be easy to use.
Result must be something like this:
2022-06-10 14:27:23:119 -0400 [compact] INFO org.slf4j.impl.App - Enabling compact logging 2022-06-10 14:27:23:120 -0400 [compact] INFO org.slf4j.impl.App - Listing entries 2022-06-10 14:27:23:120 -0400 [compact] DEBUG org.slf4j.impl.App - Calling internal process Clean up list from empty or null string Removing : "" Removing : "null" <...> 2022-06-10 14:27:23:120 -0400 [compact] DEBUG org.slf4j.impl.App - Return to Normal log
The code will be use like this:
@Slf4j public class App { public void publicCall( List<String> list ) { log.info("Enabling compact logging"); try (AutoCloseable ignored = ((CompactLogger)log).beginCompactLogging()) { processList(list); } catch (Exception e) { log.error("Process issue", e); } log.debug("Return to Normal log"); } }
Related to: Slf4j-552.