[slf4j-user] amending messages

Vitaliy Semochkin vitaliy.se at gmail.com
Tue Feb 24 17:32:46 CET 2015


Thank you very much for fast reply Joachim!

I was hopping to do it via slf4j API, because my framework users often use
log4j together with slf4j.

The question remains:
Is there a way to tell LoggerFactory to instantiate a Logger instance and
wrap it with my Logger (which will amend messages)?

Regards,
Vitaliy S


On Tue, Feb 24, 2015 at 1:45 PM, Joachim Durchholz <jo at durchholz.org> wrote:

> Am 23.02.2015 um 20:20 schrieb Vitaliy Semochkin:
>
>> Now i'm trying to solve a  problem of amending the messages
>> that were sent to slf4j directly (e.g. by Hibernate). I want to place
>> a proper indent into the beginning of a message.
>> How can I do it?
>>
>
> Building a ch.qos.logback.core.Appender should do the trick.
> You may want to make an Appender that inserts the indent into the messages
> an delegates to another Appender, so that applications can still configure
> for arbitrary receivers.
>
> How to tell the Appender how far to indent is the intereting part. SLF4J
> is a very narrow interface (by design), but you could use a Marker or the
> MDC (I never understood the specific criteria when to prefer a Marker over
> the MDC, somebody might want to clarify that).
>
> I see two approaches: signal just indent and dedent, or send the absolute
> indent level and let the Appender sort things out.
>
> Signalling just indent and dedent will automatically skip indentations for
> message levels that never get sent. I.e. the output won't suddenly indent
> by five levels just because the code happens to emit messages five levels
> deep, of which four higher levels of messages don't get printed anyway.
> The downside is that some weird filter misconfiguration might swallow an
> indent-carrying log message and let the dedent-carrying one through, or
> vice versa.
>
> Sending absolute indent levels means that you need to keep track of the
> indent level in the code above SLF4J.
> I didn't want to do that so I wouldn't have to incur the overhead of my
> own Logger delegating to an SLF4J Logger, but I found I'd have to do that
> delegation for other reasons - maybe that's something you tend to end up
> doing anyway. YMMV.
>
> HTH
> Jo
> _______________________________________________
> slf4j-user mailing list
> slf4j-user at qos.ch
> http://mailman.qos.ch/mailman/listinfo/slf4j-user
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.qos.ch/pipermail/slf4j-user/attachments/20150224/371251b4/attachment.html>


More information about the slf4j-user mailing list