Uploaded image for project: 'SLF4J'
  1. SLF4J
  2. SLF4J-552

Disable pattern programatically in current thread.

    XMLWordPrintable

Details

    • Icon: New Feature New Feature
    • Resolution: Won't Fix
    • Icon: Minor Minor
    • None
    • None
    • slf4j-simple
    • None
    • enhancement

    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. Sadly I do not know who is in the top of the pyramide. Slf4j seem to be the place to begin with.

      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:Logback-1645

      Attachments

        Activity

          People

            slf4j-dev SLF4J developers list
            Poitras Martin
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: