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

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

LoggerConfig delegates LogEvent creation to a (configurable) LogEventFactory. I 
see two ways to set the nanoTime value on the resulting LogEvent without 
breaking existing {{LogEventFactory}} implementations:

# Update the built-in factory implementation {{DefaultLogEventFactory}} to call 
the new Log4jLogEvent constructor with the additional nanoTime parameter. 
# Add a {{setNanoTime}} method to {{LogEvent}} and initialize its value after 
the factory created the event.

Solution 1 has the advantage that it allows us to make nanoTime a read-only 
(final) field on Log4jLogEvent but it only works for the built-in factory 
implementation. Custom implementations would need to be modified by their 
authors to call the new constructor or the resulting LogEvents will not have a 
nanoTime value.

Solution 2 allows us to support nanoTime timestamps even with custom 
{{LogEventFactory}} implementations. The drawback is that it requires the 
{{LogEvent}} interface and all implementations to have the additional 
{{setNanoTime}} method.

Now that I've organized my thoughts by writing them down :-) I am thinking 
solution 2 is the better trade-off. Let me know if anyone disagrees.

> 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
>            Assignee: Remko Popma
>
> 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