DummyNanoClock vs SystemNanoClock?! #3197
-
I am trying to understand how the various clock implementations in log4j2 works and I found the org.apache.logging.log4j.core.util.SystemNanoClock in the documentation but for me another class DummyNanoClock is instead used (or at least that is what is returned when I call the getNanoClock() method in LogManager.getContext(false).getConfiguration()). What is the use of these two classes? Why is the "dummy" used and when /why is SystemNanoClock used? There is also a PreciseClock interface but this also seem to only return time with millisecond precision... I have specified Just for fun I tried specifying the property -Dlog4j.Clock=org.apache.logging.log4j.core.util.SystemNanoClock but this resulted in a class cast exception so this setting seem to be for setting some other clock and not the "nanoclock" or what am I missing here...?! Anybody that can explain? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
In Log4j Core there two different types of time sources:
Since you are using
Remark: Note that in Log4j Core |
Beta Was this translation helpful? Give feedback.
-
Thanks for the good explanation - now more clear for me! |
Beta Was this translation helpful? Give feedback.
In Log4j Core there two different types of time sources:
o.a.l.l.core.util.Clock
and its subinterfaceo.a.l.l.core.util.PreciseClock
: these sources return the current date and time with different degrees of precision. On POSIX systems they correspond to theCLOCK_REALTIME
constant ofclock_gettime
.This is the source used by the date pattern converter (
%d
).o.a.l.l.core.util.NanoClock
returns the numbers of nanoseconds from an arbitrary point in time. On POSIX systems they correspond to theCLOCK_MONOTONIC
constant. On Linux this gives the number of nanoseconds from the system boot time.This is the source used by the nanosecond pattern converter (
%N
).Since you are using
%d
, you want aP…