Log4j 2
  1. Log4j 2
  2. LOG4J2-415

Format log event time as UNIX time (seconds or milliseconds).

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.0-rc1
    • Component/s: Layouts
    • Labels:
      None
    • Environment:

      Description

      Format log event time as UNIX time.

      This patch proposes two solutions, we should pick one.

      Either use %d

      {UNIX}

      and modify the existing DatePatternConverter which makes the class a tiny bit more convoluted.

      Or, create a new UnixTimePatternConverter, which is simple, but duplicates the pattern of DatePatternConverter.

      Discuss!

      1. Log4j2-415.diff
        11 kB
        Gary Gregory

        Activity

        Gary Gregory created issue -
        Hide
        Gary Gregory added a comment -

        Patch proposal.

        Show
        Gary Gregory added a comment - Patch proposal.
        Gary Gregory made changes -
        Field Original Value New Value
        Attachment Log4j2-415.diff [ 12606135 ]
        Hide
        Remko Popma added a comment -

        I would prefer the separate UnixTimePatternConverter. It seems cleaner, simpler and easier to maintain.
        I also suspect it may have slightly better performance (less conditionals to execute at runtime), but I'm not sure if the difference will be significant.

        Show
        Remko Popma added a comment - I would prefer the separate UnixTimePatternConverter. It seems cleaner, simpler and easier to maintain. I also suspect it may have slightly better performance (less conditionals to execute at runtime), but I'm not sure if the difference will be significant.
        Hide
        Gary Gregory added a comment -

        I like the separate converter too from a code maintenance POV because it does the job differently from the current date pattern converter.

        From a user's POV, I wonder if it will be confusing that a date format has to be used outside of the usual %d

        {...}

        format. It clearly is NOT a date format, so from that POV it should not be confusing.

        Show
        Gary Gregory added a comment - I like the separate converter too from a code maintenance POV because it does the job differently from the current date pattern converter. From a user's POV, I wonder if it will be confusing that a date format has to be used outside of the usual %d {...} format. It clearly is NOT a date format, so from that POV it should not be confusing.
        Hide
        Remko Popma added a comment -

        I see...
        Would it be possible to instantiate a UnixTimePatternConverter for pattern %d{UNIX}, and a DatePatternConverter for any other date pattern?

        Show
        Remko Popma added a comment - I see... Would it be possible to instantiate a UnixTimePatternConverter for pattern %d{UNIX }, and a DatePatternConverter for any other date pattern?
        Hide
        Gary Gregory added a comment -

        Well, I'm sure it's possible but it sure sounds ugly at least from glancing at how to do this in the current code.

        Show
        Gary Gregory added a comment - Well, I'm sure it's possible but it sure sounds ugly at least from glancing at how to do this in the current code.
        Hide
        Ralph Goers added a comment - - edited

        1. I prefer %d{UNIX} over %ut.
        2. No, you cannot have a separate converter based on a parameter to the converter (The %key represents the name of the converter). Although the DatePatternConverter could delegate to another class to handle the Unix formatting I doubt it would be worth the effort.

        Show
        Ralph Goers added a comment - - edited 1. I prefer %d{UNIX} over %ut. 2. No, you cannot have a separate converter based on a parameter to the converter (The %key represents the name of the converter). Although the DatePatternConverter could delegate to another class to handle the Unix formatting I doubt it would be worth the effort.
        Gary Gregory made changes -
        Summary Format log event time as UNIX time. Format log event time as UNIX time (seconds or milliseconds).
        Hide
        Gary Gregory added a comment -

        I reworked the code in the date converter solution to be more OO. This is now in SVN. Use %d{UNIX} and %d{UNIX_MILLIS}. I updated the manual as well.

        Show
        Gary Gregory added a comment - I reworked the code in the date converter solution to be more OO. This is now in SVN. Use %d{UNIX } and %d{UNIX_MILLIS }. I updated the manual as well.
        Gary Gregory made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Fix Version/s 2.0-rc1 [ 12325011 ]
        Resolution Fixed [ 1 ]

          People

          • Assignee:
            Gary Gregory
            Reporter:
            Gary Gregory
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development