[
https://issues.apache.org/jira/browse/LOG4J2-3075?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17341818#comment-17341818
]
Volkan Yazici commented on LOG4J2-3075:
---------------------------------------
This issue has turned out to be a pretty difficult one to crack. I have done
some preliminary study and checked {{DatePatternConverter}} for inspiration. In
a nutshell, this is what {{DataPatternConverter}} does:
{code:java}
private Formatter createFormatter(final String[] options) {
final FixedDateFormat fixedDateFormat =
FixedDateFormat.createIfSupported(options);
if (fixedDateFormat != null) {
return createFixedFormatter(fixedDateFormat);
}
return createNonFixedFormatter(options);
}
{code}
If {{FixedDateFormat}} supports the user pattern, it uses the
{{FixedDateFormat}}, otherwise it falls back to {{FastDateFormat}}. Here comes
the tricky part... {{FixedDateFormat#formatInstant()}} supports nanoseconds
passed in by the Log4j {{Instant}} argument. Though {{FastDateFormat}} doesn't
format nanoseconds at all, it is worse: in essence it is designed to work with
{{Calendar}} instances which doesn't support nanosecond precision! Hence, if
the user pattern is not supported by the {{FixedDateFormat}}, the fallback
{{FastDateFormat}} doesn't support nanoseconds. As a consequence,
{{PatternLayout}} doesn't support nanosecond either, _if_ the provided pattern
cannot be formatted via {{FixedDateFormat}}. The solution I have in mind is to
extend {{FastDateFormat}} to support nanoseconds. Though this necessitates
substantial rewrite of the {{FastDatePrinter}} used by {{FastDateFormat}}.
Apparently, this story kicks the hornets' nest.
> JsonTemplateLayout timestamp resolver doesn't format nanoseconds
> ----------------------------------------------------------------
>
> Key: LOG4J2-3075
> URL: https://issues.apache.org/jira/browse/LOG4J2-3075
> Project: Log4j 2
> Issue Type: Bug
> Components: JsonTemplateLayout
> Affects Versions: 2.14.0, 2.14.1
> Reporter: Paul Rubin
> Assignee: Volkan Yazici
> Priority: Minor
> Fix For: 3.0.0, 2.15.0
>
>
> As reported in LOG4J2-3073, {{TimestampResolver}} of {{JsonTemplateLayout}}
> doesn't format nanoseconds. The suspect is in the following form:
> {code:java}
> formatResolverContext.calendar.setTimeInMillis(timestampMillis);
> formatResolverContext.timestampFormat.format(
> formatResolverContext.calendar,
> formatResolverContext.formattedTimestampBuilder);
> {code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)