<div dir="ltr"><div><div><div>Thank you very much for fast reply Joachim!<br><br></div>I was hopping to do it via slf4j API, because my framework users often use log4j together with slf4j.<br><br></div><div>The question remains:<br></div>Is there a way to tell LoggerFactory to instantiate a Logger instance and wrap it with my Logger (which will amend messages)?<br><br></div><div><div>Regards,<br></div><div>Vitaliy S<br></div><div><div><br></div></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Feb 24, 2015 at 1:45 PM, Joachim Durchholz <span dir="ltr"><<a href="mailto:jo@durchholz.org" target="_blank">jo@durchholz.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Am 23.02.2015 um 20:20 schrieb Vitaliy Semochkin:<span class=""><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Now i'm trying to solve a  problem of amending the messages<br>
that were sent to slf4j directly (e.g. by Hibernate). I want to place<br>
a proper indent into the beginning of a message.<br>
How can I do it?<br>
</blockquote>
<br></span>
Building a ch.qos.logback.core.Appender should do the trick.<br>
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.<br>
<br>
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).<br>
<br>
I see two approaches: signal just indent and dedent, or send the absolute indent level and let the Appender sort things out.<br>
<br>
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.<br>
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.<br>
<br>
Sending absolute indent levels means that you need to keep track of the indent level in the code above SLF4J.<br>
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.<br>
<br>
HTH<br>
Jo<br>
______________________________<u></u>_________________<br>
slf4j-user mailing list<br>
<a href="mailto:slf4j-user@qos.ch" target="_blank">slf4j-user@qos.ch</a><br>
<a href="http://mailman.qos.ch/mailman/listinfo/slf4j-user" target="_blank">http://mailman.qos.ch/mailman/<u></u>listinfo/slf4j-user</a><br>
</blockquote></div><br></div>