Uploaded image for project: 'logback'
  1. logback
  2. LOGBACK-1658

LayoutPattern does not support nanoseconds format

    XMLWordPrintable

Details

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • 1.5.7
    • 1.3.0-beta0
    • logback-classic
    • None

    Description

      PatternLayout trims the event timestamp down to milliseconds precision irrespective of the configured pattern.

      For instance the following config:

      <appender name="LOGBACK" class="ch.qos.logback.core.ConsoleAppender">
         <encoder>
            <pattern>%date{dd-MM-yyyy'T'HH:mm:ss.n} - %msg%n</pattern>
         </encoder>
      </appender> 

      produces output like the following:

      13-08-2022T16:05:49.211000000 - A sample log message (0)
      13-08-2022T16:05:49.213000000 - A sample log message (1)
      13-08-2022T16:05:49.213000000 - A sample log message (2)
      13-08-2022T16:05:49.213000000 - A sample log message (3)
      13-08-2022T16:05:49.213000000 - A sample log message (4)
      13-08-2022T16:05:49.213000000 - A sample log message (5)

      As you can see although the pattern asks for nanoseconds after the seconds only the millis are actually output with the nano parts set to zero.

      A quick look at the code reveals that the DateConverter gets the timestamp from the ILoggingEvent by calling ILoggingEvent#getTimeStamp() which gives the timestamp in millis instead of the new ILoggingEvent#getInstant().

      See https://github.com/qos-ch/logback/blob/master/logback-classic/src/main/java/ch/qos/logback/classic/pattern/DateConverter.java#L59-L62.

       

      Attachments

        Activity

          People

            ceki Ceki Gülcü
            brenuart Bertrand Renuart
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: