[logback-user] Timing of sifting appender dynamic appender instantiation

Stuart Rossiter stuart.p.rossiter at gmail.com
Thu Apr 11 16:18:23 CEST 2013


On 11 April 2013 14:34, diroussel <nabble at diroussel.xsmail.com> wrote:

> I'm using logback 1.0.9 and this works for me.
>
> When I set an MDC key, then the very next log statement will cause it to go
> to a new appender and new log file.
>

Yes, this does happen for me as well. What I mean is that Logback only adds
the appender dynamically *within the log statement method*, rather than as
soon as the MDC key is set.

This is a problem for me because I want to amend the dynamically created
appender (replacing the encoder with my own) *before* logging anything. As
in my original msg, the wording in the manual strongly suggests that the
appender is created at MDC put-time, and so is misleading. It would also
seem more 'correct' to support use cases like mine.

(There's also a secondary issue: currently one *must* specify an encoder in
the config file for the dynamically created sub-appender. It would be
better if one could omit the encoder when one knew that one was adding
one's own, avoiding the unnecessary initialisation. It perhaps also fits
better conceptually: an appender will just do nothing until an encoder is
added, rather than requiring the full 'stack' of
appender-->encoder-->layout before being able to start.)


>
> What do you mean that you need to send a spurious message first?
>

I log a message to actually trigger the sub-appender addition. (I don't
want to do this since it is using an encoder which I don't want to use.)
Hope that makes it clearer!


>
> David
>
>
Many thanks for the response anyway.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.qos.ch/pipermail/logback-user/attachments/20130411/2308b3d5/attachment.html>


More information about the Logback-user mailing list