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

Anthony Maire commented on LOG4J2-1883:
---------------------------------------

Concerning the java.time.Instant allocation, I made a JMH test with JDK 
1.8.0_171, and as I suspected, the allocation is removed because of escape 
analysis.
Here is the body of the method under test :
{code}
    @Benchmark
    public long updateTimeStamp(CustomTimestamp timestamp){
        Instant now = clock.instant();
        timestamp.secondsFromEpoch = now.getEpochSecond();
        timestamp.nanoSeconds = now.getNano();
        return timestamp.nanoSeconds + timestamp.secondsFromEpoch;
    }
{code}

where clock is initialized by java.time.clock.systemUTC()
JMH built in gc profiler reported less than 1 byte allocated by benchmark 
iteration (which is probably caused by JMH itself)
I double checked with Java Mission Control, and no Instant was allocated during 
a 15 min run.
JMH returned a 20ns average time, so the code should be not eliminated by the 
JIT compiler.

Another test should be done on Java 9, since the clock.instant() method is a 
little more complex and maybe the escape analysis doesn't work there, but at 
first sight, it seems than the allocation issue can be avoided.
However I don't know if relying on escape analysis is an acceptable way of 
conform with the 0-allocation policy, since it is VM dependant.

> 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.3.15#6346)

Reply via email to