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

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

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 2.0-rc1
    • Layouts
    • None

    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!

      Attachments

        1. Log4j2-415.diff
          11 kB
          Gary D. Gregory

        Activity

          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.

          ggregory Gary D. 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.
          rgoers 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.

          rgoers 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.

          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.

          ggregory Gary D. 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.
          rpopma 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?

          rpopma 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?

          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.

          ggregory Gary D. 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.
          rpopma 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.

          rpopma 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.

          Patch proposal.

          ggregory Gary D. Gregory added a comment - Patch proposal.

          People

            ggregory Gary D. Gregory
            ggregory Gary D. Gregory
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: