<div dir="ltr"><div>The reason I need to modify MDC properties is that there are a lot of<span style="color:rgb(255,0,0)"><b> framework/library generated threads</b></span>. Also they are dynamically start and stop.<br></div>
<div>Those threads are <b>not accessible</b> to me.<br></div><div>When I use log4j/RewriteAppender, I can put properties without care about threads' accessibility like the following.<br><pre class=""><span class=""><span class=""><appender</span> <span class="">name</span>=<span class="">"stdoutaddprops"</span> <span class="">class</span>=<span class="">"org.apache.log4j.rewrite.<span class="">RewriteAppender</span>"</span><span class="">></span></span>
<span class=""><span class=""><appender-ref</span> <span class="">ref</span>=<span class="">"stdout"</span> <span class="">/></span></span>
<span class=""><span class=""><rewritePolicy</span> <span class="">class</span>=<span class="">"org.apache.log4j.rewrite.PropertyRewritePolicy"</span><span class="">></span></span>
<span class=""><span class=""><param</span> <span class="">name</span>=<span class="">"properties"</span> <span class="">value</span>=<span class="">"p1=Hello,p2=World,x1=3.1415,username=${<a href="http://user.name">user.name</a>}"</span><span class="">/></span></span> <!-- here, add some MDC properties -->
<span class=""><span class=""></rewritePolicy<span class="">></span></span></span>
<span class=""><span class=""></appender<span class="">></span></span></span></pre></div><div><br></div><div>Is this possible to call MDC.put() for <b>inaccessible threads</b>?<br><br></div></div><div class="gmail_extra">
<br><br><div class="gmail_quote">2013/7/10 Ralph Goers <span dir="ltr"><<a href="mailto:rgoers@apache.org" target="_blank">rgoers@apache.org</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word"><div><br></div><div>This will modify the MDC, not just the properties in the logging event, which seems to be what was requested.<span class="HOEnZb"><font color="#888888"><div><br></div>
<div>Ralph</div></font></span></div><div><div class="h5"><div><br></div><div><br></div><div><div>On Jul 9, 2013, at 7:55 AM, Felipe wrote:</div><br><blockquote type="cite"><div dir="ltr">That should be easy. Juast add import correct classes and then do at proper section (posiblt the init of the thread) MDC.put(key, value).</div>
<div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Jul 9, 2013 at 10:35 AM, KwonNam Son <span dir="ltr"><<a href="mailto:kwon37xi@gmail.com" target="_blank">kwon37xi@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><p>Hello,<br></p><p>When I use Log4j, I can add MDC properties to <a href="http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/spi/LoggingEvent.html" rel="nofollow" target="_blank">LogginEvent</a> by using <a href="http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/rewrite/RewriteAppender.html" rel="nofollow" target="_blank">RewriteAppender</a>.
It's possible because log4j's LoggingEvent is not an interface and it has <a href="http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/spi/LoggingEvent.html#setProperty%28java.lang.String,%20java.lang.String%29" rel="nofollow" target="_blank">setProperty()</a> method.</p>
<p>Is it possible to add or modify MDC properties dynamically in Logback?</p><p>The reason I need to change MDC properties using appenders is because
of some logs from unaccessible threads.
I want to add hostname, application name and some of server's infomation
to the logs then transfer the logs event to the central log receiver.</p><p><br></p><p>Thanks.<br></p><br></div></div>
<br>_______________________________________________<br>
Logback-user mailing list<br>
<a href="mailto:Logback-user@qos.ch" target="_blank">Logback-user@qos.ch</a><br>
<a href="http://mailman.qos.ch/mailman/listinfo/logback-user" target="_blank">http://mailman.qos.ch/mailman/listinfo/logback-user</a><br></blockquote></div><br><br clear="all"><div><br></div>-- <br>Felipe
</div>
_______________________________________________<br>Logback-user mailing list<br><a href="mailto:Logback-user@qos.ch" target="_blank">Logback-user@qos.ch</a><br><a href="http://mailman.qos.ch/mailman/listinfo/logback-user" target="_blank">http://mailman.qos.ch/mailman/listinfo/logback-user</a></blockquote>
</div><br></div></div></div><br>_______________________________________________<br>
Logback-user mailing list<br>
<a href="mailto:Logback-user@qos.ch">Logback-user@qos.ch</a><br>
<a href="http://mailman.qos.ch/mailman/listinfo/logback-user" target="_blank">http://mailman.qos.ch/mailman/listinfo/logback-user</a><br></blockquote></div><br><br clear="all"><br>-- <br>* ±î¸ÔÁö¸»ÀÚ! <a href="http://kwon37xi.egloos.com">http://kwon37xi.egloos.com</a>
</div>