<div dir="ltr"><br><div class="gmail_extra"><div class="gmail_quote">On 16 April 2013 15:25, diroussel <span dir="ltr"><<a href="mailto:nabble@diroussel.xsmail.com" target="_blank">nabble@diroussel.xsmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Using MDC would be the normal way.  Just set your SimTime in the MDC each<br>
time you change configuration.<br>
<br>
Not sure how doing it in a custom injected Layout makes it any easer?<br><br></blockquote></div><div></div><div><br></div><div style>Well, it's a much cleaner code design my way (IMO). At decreasing levels of bad design, I could:</div>
<div style><br></div><div style>(a) Add the simulation time within each message explicitly</div><div style>e.g. <a href="http://logger.info">logger.info</a>(formatSimTime() + "My widget was wangled");</div><div style>
<br></div><div style>[horrible 'leakage' into each logging call]</div><div style><br></div><div style>(b) Add it in a global logging function:</div><div style>e.g. myLogging.info("My widget was wangled");</div>
<div style><br></div><div style>[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]</div>
<div style><br></div><div style>(c) Set MDC before each call and then extract that via the pattern layout</div><div style><br></div><div style>[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.]</div>
<div style><br></div><div style>(d) Use a custom layout that adds the sim time transparently to the code</div><div style><br></div><div style>[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]</div>
<div style><br></div><div style><br></div>
</div></div>