[ 
https://issues.apache.org/jira/browse/LOG4J2-1883?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16092387#comment-16092387
 ] 

Remko Popma commented on LOG4J2-1883:
-------------------------------------

[~garydgregory] This JIRA ticket is not about Java 8. As Ralph and Anthony 
pointed out earlier, the new {{Instant.getNano()}} API does not help because 
the clock in Java 8 is still millisecond granularity.  At best, Java 8 would 
give us formatting convenience. And bear in mind, neither the Instant API nor 
the {{java.util.time}} formatters are garbage free. Even in Java 9, we would 
finally get a precise clock, but again we would be allocating temporary objects 
for every time stamp and every time we format with the jdk formatters...

[~Anthony Maire] Thanks again for the in-depth analysis and the clear write up. 
I agree with your proposal to encode time as nanoseconds since the epoch in a 
long and store it in the existing LogEvent.nanoTime field. I'm fine with not 
supporting timestamps later than year 2262. For formatting, please take a look 
at the 
[FixedDateFormat|https://github.com/apache/logging-log4j2/blob/master/log4j-core/src/main/java/org/apache/logging/log4j/core/util/datetime/FixedDateFormat.java#L26]
 class. I would not mind modifying that class to support formatting 
nanos-since-epoch time. An alternative is to format in two phases, where we 
first convert back to millis to use existing formatters, then append the nanos 
portion, like you described 
[above|https://issues.apache.org/jira/browse/LOG4J2-1883?focusedCommentId=16055753&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-16055753].
 I would prefer to have a single pattern converter 
"%preciseTime\{format,precision}" or something rather than combining two 
converters like %d\{ISO8601}%sm\{3}, but I could be convinced otherwise. 
Looking forward to your fork!

> Timestamp does not seem to support microseconds level
> -----------------------------------------------------
>
>                 Key: LOG4J2-1883
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-1883
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Configurators
>         Environment: Linux with any JDK including JDK1.8
>            Reporter: Madhava Dass
>            Priority: Critical
>
> Used log4j and 'log4j2.xml' to configure timestamp format as:
> {code}
> <?xml version="1.0" encoding="UTF-8"?>
> <Configuration status="WARN">
>     <Appenders>
>         <Console name="Console" target="SYSTEM_OUT">
>             <PatternLayout 
> pattern="[%d{yyyy-MM-dd'T'HH:mm:ss.SSSXXX}{UTC}][%level][%logger{36}]:%msg%n"/>
>         </Console>
>     </Appenders>
>     <Loggers>
>         <Root level="DEBUG">
>             <AppenderRef ref="Console"/>
>         </Root>
>     </Loggers>
> </Configuration>
> {code}
> This pattern produces the time stamp as:
> {code}
> [2017-03-29T13:55:28.363000][null]:[Thread-1]: - <message>
> {code}
> The desired output is:
> {code}
> [2017-03-29T13:55:28.363701-07:00][null]:[Thread-1]: - <message>
> {code}
> Different versions of JDKs were tried including JDK 1.8. It does not seem to 
> make any difference in the outcome.
> Is there a way to get the desired time stamp through pattern matching 
> configuration in the '*.xml' file?



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to