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

Remko Popma commented on LOG4J2-1074:
-------------------------------------

I imagine using Log4j as a quick and easy benchmarking tool is actually a 
fairly common use case. So I would like to support it. However, I hesitate to 
call {{System.nanoTime()}} for every {{LogEvent}} if the value is not used 
downstream.

One solution is to introduce a {{NanoClock}} interface for producing these 
values (similarly to the Clock interface we use for the millisecond values). 
{{Configuration.getNanoClock()}} would return the NanoClock in use. For every 
{{LogEvent}}, we initialize its nanoTime value by calling 
{{Configuration.getNanoClock().nanoTime()}}. By default the Configuration would 
have a dummy NanoClock that always returns zero. If any of the layouts in the 
configuration file contains a {{NanoTimePatternConverter}} - the new format 
specifier for nano time - then a real clock would be created which calls 
{{System.nanoTime()}}.

And of course, the {{LogEvent}} interface would need to have an additional 
method {{getNanoTime()}}.

Thoughts?

> Add a logformat token for nanotime
> ----------------------------------
>
>                 Key: LOG4J2-1074
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-1074
>             Project: Log4j 2
>          Issue Type: New Feature
>            Reporter: Will Hains
>
> Add a token in the log format specifier to output the current value of 
> {{System.nanotime()}}.
> We are currently adding the nanotime value to our log messages manually, 
> which we find very useful for troubleshooting unexpected latency, and as a 
> quick-and-dirty data source to feed into performance analysis tools.
> It would be very nice if Log4j could do this for us. It would also be nice to 
> have this in the log format specified, so we can turn it on/off at runtime by 
> editing the Log4j config file.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to