Using MDC would be the normal way. Just set your SimTime in the MDC each
time you change configuration.
Not sure how doing it in a custom injected Layout makes it any easer?
Well, it's a much cleaner code design my way (IMO). At decreasing levels of bad design, I could:
(a) Add the simulation time within each message explicitly
e.g. logger.info(formatSimTime() + "My widget was wangled");
[horrible 'leakage' into each logging call]
(b) Add it in a global logging function:
e.g. myLogging.info("My widget was wangled");
[takes the standard SLF4J interface away from the coder, and they have to remember to use this wrapper. Also always means the sim time is after any other Logback pattern fields in the log, when I really want this to act as a replacement for the commonly-used system time field]
(c) Set MDC before each call and then extract that via the pattern layout
[Same leakage into the code as (b), though fixes the time position in the message. Messy because I am partitioning logs by thread as well, also using MDC values. Will also be bombarding Logback with new MDC values.]
(d) Use a custom layout that adds the sim time transparently to the code
[Chosen solution. This can't be set up in the Logback config file because the layout requires references to internal simulation objects to get the simulation time. Hence my requirement to create an appender (via sifting appender for the per-thread separation) either without an encoder (ideally) or with a dummy one, and then set up the encoder programmatically at run-time initialisation]