Yes, thanks for the information. I worked around the problem.

Thanks,
Atul

From: Remko Popma <remko.po...@gmail.com>
Date: Thursday, 30 December 2021 at 4:13 PM
To: Log4J Users List <log4j-user@logging.apache.org>
Subject: Re: RFC5424Layout - How to format timestamp with microsecond precision
The class I was talking about is in the core jar.
This is a multi release jar 
(https://docs.oracle.com/javase/10/docs/specs/jar/jar.html#multi-release-jar-files),
 and the class I was talking about is in the core jar in the 
META-INF/versions/9  directory.

But you have resolved the problem?



> On Dec 30, 2021, at 16:55, Atul Pendse <apen...@tintri.com.invalid> wrote:
>
> BTW.. I am using java 11, with unnamed module.
>
> Thanks,
> Atul
>
> From: Atul Pendse <apen...@tintri.com.INVALID>
> Date: Thursday, 30 December 2021 at 1:24 PM
> To: Log4J Users List <log4j-user@logging.apache.org>
> Subject: Re: RFC5424Layout - How to format timestamp with microsecond 
> precision
> Sorry, I hit send button prematurely.
>
> I worked around the issue by explicitly setting Configuration.nanoClock to 
> SystemNanoClock, only if nano precision is required. Similar to how 
> PatternParser does it.
>
> I see below code in PatternParser
>
>            if (converter instanceof NanoTimePatternConverter) {
>                // LOG4J2-1074 Switch to actual clock if nanosecond timestamps 
> are required in config.
>                // LOG4J2-1248 set config nanoclock
>                if (config != null) {
>                    config.setNanoClock(new SystemNanoClock());
>                }
>            }
>
> On similar line, I handled my customized Rfc5424Layout
>
>        if ( TIME_PRECISION_MICRO.equalsIgnoreCase( timestampPrecision ) && !( 
> configuration.getNanoClock() instanceof SystemNanoClock ) ) {
>            configuration.setNanoClock( new SystemNanoClock() );
>        }
>
> Time precision is a new attribute that I added in my copy of source.
>
> Thanks,
> Atul
>
> From: Atul Pendse <apen...@tintri.com>
> Date: Thursday, 30 December 2021 at 1:16 PM
> To: Log4J Users List <log4j-user@logging.apache.org>
> Subject: Re: RFC5424Layout - How to format timestamp with microsecond 
> precision
> Ok, I am confused about log4j-core-java9
> I am using below jars
>
> Log4j-core-2.17.0.jar
> Log4j-api-2.17.0.jar
>
> I don’t see anything like log4j-core-java9-2.17.0.jar on maven. Where can I 
> find it?
>
> In my environment, ClockFactory is creating instance of SystemClock, which 
> looks like below
>
> package org.apache.logging.log4j.core.util;
> /**
> * Implementation of the {@code Clock} interface that returns the system time.
> */
> public final class SystemClock implements Clock {
>
>    /**
>     * Returns the system time.
>     * @return the result of calling {@code System.currentTimeMillis()}
>     */
>    @Override
>    public long currentTimeMillis() {
>        return System.currentTimeMillis();
>    }
>
> }
>
> I see no way it can support nanoseconds.
>
> From: Remko Popma <remko.po...@gmail.com>
> Date: Thursday, 30 December 2021 at 12:53 PM
> To: Log4J Users List <log4j-user@logging.apache.org>
> Subject: Re: RFC5424Layout - How to format timestamp with microsecond 
> precision
> Atul,
>
> The nanoClock is not used for the formatted timestamps. It just outputs the
> result of System.nanoTime(). It is used for %N or %nano in PatternLayout.
>
> If you are running on Java 9 or later, then the default clock
> is 
> log4j-core-java9/src/main/java/org/apache/logging/log4j/core/util/SystemClock.java
> (Note that there is another class, also called SystemClock, in the same
> package, in log4j-core/src.)
>
> The SystemClock that is loaded on Java 9 and later implements both the
> Clock and the PreciseClock interface.
> Log4jLogEvent has a field 'instant' of type MutableInstant; this field is
> initialized from the Clock.
> (There is a Log4jLogEvent constructor where the instant is not initialized
> from the Clock, but I believe this is only used in special cases.)
>
> So, I don't believe that Log4jLogEvent should prevent you from seeing
> sub-millisecond timestamps.
> Something else must be the problem.
>
> Can you verify that in your environment, the Log4jLogEvent's CLOCK (the
> result of calling ClockFactory.getClock()) implements
> org.apache.logging.log4j.core.time.PreciseClock?
>
>
>
>
>
>
>> On Thu, Dec 30, 2021 at 4:04 PM Ralph Goers <ralph.go...@dslextreme.com>
>> wrote:
>>
>> 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
>>
>>

Reply via email to