[
https://issues.apache.org/jira/browse/LOG4J2-1883?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16342097#comment-16342097
]
Remko Popma edited comment on LOG4J2-1883 at 1/27/18 11:50 AM:
---------------------------------------------------------------
Summary of the changes that were made to support precise timestamps:
*API Changes*
Introduced interface {{Instant}} and implementation {{MutableInstant}}. Some
time sources and time consumers can produce/consume in the Java 8-like "epoch
second + nanoOfSecond" format, while for others it is convenient to also have a
"epoch millisecond + nanoOfMillisecond" format. {{Instant}} can translate
between these two formats and {{MutableInstant}} can be initialized from either
format.
The {{LogEvent}} interface now has an additional {{getInstant}} method. In all
implementations the existing {{getTimeMillis}} method is now implemented based
on the {{getInstant}} method.
*Clock*
LogEvent implementations are responsible for getting the most precise
timestamp possible from the clock: if the current clock implements
{{PreciseClock}}, then let this clock initialize the event's {{MutableInstant}}.
The {{log4j-core-java9}} module has a {{SystemClock}} class that implements
{{PreciseClock}} and uses the Java 8 time API to get a {{java.time.Instant}}
used to initialize our MutableInstant. When running on Java 9, log events will
have nanosecond precision timestamps by default.
*Pattern Layout*
PatternLayout has additional options for the {{%d}} date format specifier:
* {{%d\{DEFAULT_MICROS\}}} - e.g. {{2012-11-02 14:34:02,123456}}
* {{%d\{DEFAULT_NANOS\}}} - e.g. {{2012-11-02 14:34:02,123456789}}
* {{%d\{ABSOLUTE_MICROS\}}} - e.g. {{14:34:02,123456}}
* {{%d\{ABSOLUTE_NANOS\}}} - e.g. {{14:34:02,123456789}}
* {{%d\{HH:mm:ss,nnnn\} to %d\{HH:mm:ss,nnnnnnnnn\}}} - e.g. {{14:34:02,1234
to 14:34:02,123456789}}
* {{%d\{dd MMM yyyy HH:mm:ss,nnnn\} to %d\{dd MMM yyyy HH:mm:ss,nnnnnnnnn}}} -
e.g. {{02 Nov 2012 14:34:02,1234 to 02 Nov 2012 14:34:02,123456789}}
*Serialized Form*
Changes to all classes that serialize and deserialize {{LogEvent}} objects to
store the precise time:
* The XML, JSON and YAML formats now have a new {{<Instant
epochSecond="1515889414" nanoOfSecond="144000000"/>}} element.
* POTENTIAL BREAKING CHANGE: {color:red}The XML, JSON and YAML formats no
longer have the {{timeMillis}} attribute{color}.
* {{Log4jLogEvent.LogEventProxy}} (responsible for java serialization) now has
an additional {{nanosOfMillisecond}} attribute
was (Author: [email protected]):
Summary of the changes that were made to support precise timestamps:
*API Changes*
Introduced interface {{Instant}} and implementation {{MutableInstant}}. Some
time sources and time consumers can produce/consume in the Java 8-like "epoch
second + nanosOfSecond" format, while for others it is convenient to also have
a "epoch millisecond + nanosOfMillisecond" format. {{Instant}} can translate
between these two formats and {{MutableInstant}} can be initialized from either
format.
The {{LogEvent}} interface now has an additional {{getInstant}} method. In all
implementations the existing {{getTimeMillis}} method is now implemented based
on the {{getInstant}} method.
*Clock*
LogEvent implementations are responsible for getting the most precise timestamp
possible from the clock: if the current clock implements {{PreciseClock}}, then
let this clock initialize the event's {{MutableInstant}}.
The {{log4j-core-java9}} module has a {{SystemClock}} class that implements
{{PreciseClock}} and uses the Java 8 time API to get a {{java.time.Instant}}
used to initialize our MutableInstant. When running on Java 9, log events will
have nanosecond precision timestamps by default.
*Pattern Layout*
PatternLayout has additional options for the {{%d}} date format specifier:
* {{%d\{DEFAULT_MICROS\}}} - e.g. {{2012-11-02 14:34:02,123456}}
* {{%d\{DEFAULT_NANOS\}}} - e.g. {{2012-11-02 14:34:02,123456789}}
* {{%d\{ABSOLUTE_MICROS\}}} - e.g. {{14:34:02,123456}}
* {{%d\{ABSOLUTE_NANOS\}}} - e.g. {{14:34:02,123456789}}
* {{%d\{HH:mm:ss,nnnn\} to %d\{HH:mm:ss,nnnnnnnnn\}}} - e.g. {{14:34:02,1234 to
14:34:02,123456789}}
* {{%d\{dd MMM yyyy HH:mm:ss,nnnn\} to %d\{dd MMM yyyy HH:mm:ss,nnnnnnnnn\}}} -
e.g. {{02 Nov 2012 14:34:02,1234 to 02 Nov 2012 14:34:02,123456789}}
*Serialized Form*
Changes to all classes that serialize and deserialize {{LogEvent}} objects to
store the precise time:
* The XML, JSON and YAML formats now have a new {{<Instant
epochSecond="1515889414" nanoOfSecond="144000000"/>}} element.
* The XML, JSON and YAML formats no longer have the {{timeMillis}} attribute
* {{Log4jLogEvent.LogEventProxy}} (responsible for java serialization) now has
an additional {{nanosOfMillisecond}} attribute
> Support precise timestamps (microsecond and nanosecond level)
> -------------------------------------------------------------
>
> Key: LOG4J2-1883
> URL: https://issues.apache.org/jira/browse/LOG4J2-1883
> Project: Log4j 2
> Issue Type: Bug
> Components: Configurators
> Environment: Java 9
> Reporter: Madhava Dass
> Assignee: Remko Popma
> 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
(v7.6.3#76005)