Is it possible that log4j2 prints user provided timestamp rather than system time?

StackOverflow https://stackoverflow.com//questions/24025398

  •  21-12-2019
  •  | 
  •  

Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top