[logback-user] Why are encoder-less appenders not consistently allowed?

Stuart Rossiter stuart.p.rossiter at gmail.com
Fri Apr 19 14:25:13 CEST 2013

On 16 April 2013 15:25, diroussel <nabble at diroussel.xsmail.com> wrote:

> 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]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.qos.ch/pipermail/logback-user/attachments/20130419/4638e926/attachment.html>

More information about the Logback-user mailing list