Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-3058

Support UNIX_NANOS in PatternLayout

    XMLWordPrintableJSON

    Details

    • Type: New Feature
    • Status: Open
    • Priority: Trivial
    • Resolution: Unresolved
    • Affects Version/s: 2.14.1
    • Fix Version/s: None
    • Component/s: Layouts
    • Labels:
      None
    • Environment:

      Tested on MacOS 10.15, Java 11.

      Description

      Hello! I would like to have access to a predefined named format for PatternLayout that yields a Unix epoch nanosecond, so that I can more easily meet requirements of log processors that ask for Unix epoch nanos. An operative example is the OpenTelemetry log format which asks for such.

      This predefined format could be called UNIX_NANOS, to fit with the existing UNIX_MILLIS from LOG4J2-1883. It also looks like the nanosecond component could be used directly from Instant. 

      Alternatively, a predefined named format to access an Instant in PatternLayout may also work, as one could extract the nano-of-second and append that to the UNIX epoch second.

      As a workaround, the following pattern seems to get close enough to a Unix epoch nanosecond. However, I find it a little messy to read, and I'm sure the performance could be improved with a dedicated format symbol:

      %d{UNIX}%replace{%d{HH:mm:ss,nnnnnnnnn}}{^[0-9:]+,}{}

      Apologies if there's a duplicate issue for this that I missed. Thank you for your consideration!

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              andrew.harris Andrew Harris
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated: