I think you want to set log4j2.clock=org.apache.logging.log4j.core.time.internal.FixedPreciseClock.
If you don’t like that implementation you can always provide your own implementation of PreciseClock and specify it on the system property. I’m not sure what performance impact that Clock implementation will have. Ralph > On Dec 29, 2021, at 11:56 AM, Atul Pendse <apen...@tintri.com.INVALID> wrote: > > Thanks for the quick response. It took me some time to get back to this due > to other priorities. > I logged a JIRA as you suggested. > > Also, meanwhile, I am trying to get it working for our project by copying > sources and modifying them. > I have add a new FixedDateFormat that has microsecond precision with RFC5424 > date format. I am using the new format in Rfc5424Layout, but I came across > another problem. > > It works fine when I run it in a standalone java app, but does not work in a > web app (like war deployed to tomcat). > > Standalone java app uses ReusableLogEventFactory to create LogEvent. It > creates a MutableLogEvent, which generates actual system nano time. > > In case of web app, log4j uses DefaultLogEventFactory, which creates > instances of Log4jLogEvent. Log4jLogEvent uses a DummyNanoClock, which always > defaults nano seconds to value 0. This means, events generated in a web app > are never going to have micro or nanosecond information. > > I can override the LogEventFactory by passing system property > ‘-DLog4jLogEventFactory=org.apache.logging.log4j.core.impl.ReusableLogEventFactory’, > but I am not really sure if there are any side effects of doing that. Does > anyone know if it’s okay to use ReusableLogEventFactory for a web app? > > Thanks, > Atul > > From: Volkan Yazıcı <vol...@yazi.ci> > Date: Thursday, 23 December 2021 at 2:29 PM > To: Log4J Users List <log4j-user@logging.apache.org> > Subject: Re: RFC5424Layout - How to format timestamp with microsecond > precision > Hello Atul, > > Your investigation of RFC5424 Layout seems to be accurate; the class > contains a hardcoded date-time formatting working on millisecond-precision > epoch-offset timestamps. I guess two things need to happen: > > 1. A new layout configuration argument where one can override the > date-time format pattern. > 2. Switching from the hardcoded date-time formatter to Log4j-provided > ones; FastDateFormat, FixedDateFormat, etc. I would suggest checking > JsonTemplateLayout's InstantFormatter – the most up-to-date one, AFAIC. > > These better be placed into a JIRA ticket followed by a GitHub PR. > > In the meantime, you can copy and adapt the source of Rfc5424Layout in your > project, change the plugin name, and use it there. This can serve you until > the feature gets implemented and shipped with a release. > > Kind regards. > > On Thu, Dec 23, 2021 at 9:38 AM Atul Pendse <apen...@tintri.com.invalid> > wrote: > >> Hi, >> >> Our application sends syslog messages to a centralized facility which >> requires timestamps to be in microsecond format. >> Our application was so far using log4j 1.12.5’s Syslog appender to send >> syslog messages, which used to format timestamps with microsecond precision. >> >> We are now upgrading to log4j 2.17.0, and don’t see any way to get >> microseconds included in timestamp for syslog. >> >> I am trying to log messages using SyslogAppender with RFC5424 layout. >> I see that RFC5424Layout.java restricts timestamp to millisecond precision >> (e.g. 2021-12-22T22:54:33.889-08:00). >> >> RFC5424 specification also mentions support for microsecond precision. >> Here is some text from >> https://datatracker.ietf.org/doc/html/rfc5424#section-6.2.3 >> >> Example 4 >> >> 2003-08-24T05:14:15.000003-07:00 >> >> This represents 24 August 2003 at 05:14:15am, 3 microseconds into the >> next second. The microsecond resolution is indicated by the >> additional digits in TIME-SECFRAC. The timestamp indicates that its >> local time is -7 hours from UTC. This timestamp might be created in >> the US Pacific time zone during daylight savings time. >> >> >> Is there a way to format timestamp with microsecond precision with >> RFC5424Layout? Or is there an alternative way to get timestamp formatted >> with microsecond precision for SyslogAppender? >> >> Any help would be highly appreciated. >> >> Thanks, >> Atul Pendse >> --------------------------------------------------------------------- To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org