Reputation:
I write an application that uses recorded data with timestamps. For this purpose I have an object that responsible to know current time (which is in the past, but still monotonic).
I wish to configure log4j2, such that printed timestamp will taken from this object and not from computer's timer. Is it possible?
Thank you.
Upvotes: 1
Views: 342
Reputation: 36844
Yes, this is possible.
You can specify system property "log4j.Clock" with the fully qualified class name of a class that implements the org.apache.logging.log4j.core.helpers.Clock
interface.
See documentation here: http://logging.apache.org/log4j/2.x/manual/async.html#AllAsync
As of version RC1, this works only for Async Loggers, but in the next release this will work for all configurations. Note that in the next release the core.helpers package has been moved to core.util.
See also https://issues.apache.org/jira/browse/LOG4J2-628 for details.
Upvotes: 1