
Hello, When I use Log4j, I can add MDC properties to LogginEvent<http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/spi/LoggingEvent.html>by using RewriteAppender<http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/rewrite/RewriteAppender.html>. It's possible because log4j's LoggingEvent is not an interface and it has setProperty()<http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/spi/LoggingEvent.html#setProperty%28java.lang.String,%20java.lang.String%29>method. Is it possible to add or modify MDC properties dynamically in Logback? 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. Thanks.

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). On Tue, Jul 9, 2013 at 10:35 AM, KwonNam Son <kwon37xi@gmail.com> wrote:
Hello,
When I use Log4j, I can add MDC properties to LogginEvent<http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/spi/LoggingEvent.html>by using RewriteAppender<http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/rewrite/RewriteAppender.html>. It's possible because log4j's LoggingEvent is not an interface and it has setProperty()<http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/spi/LoggingEvent.html#setProperty%28java.lang.String,%20java.lang.String%29>method.
Is it possible to add or modify MDC properties dynamically in Logback?
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.
Thanks.
_______________________________________________ Logback-user mailing list Logback-user@qos.ch http://mailman.qos.ch/mailman/listinfo/logback-user
-- Felipe

This will modify the MDC, not just the properties in the logging event, which seems to be what was requested. Ralph On Jul 9, 2013, at 7:55 AM, Felipe wrote:
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).
On Tue, Jul 9, 2013 at 10:35 AM, KwonNam Son <kwon37xi@gmail.com> wrote: Hello,
When I use Log4j, I can add MDC properties to LogginEvent by using RewriteAppender. It's possible because log4j's LoggingEvent is not an interface and it has setProperty() method.
Is it possible to add or modify MDC properties dynamically in Logback?
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.
Thanks.
_______________________________________________ Logback-user mailing list Logback-user@qos.ch http://mailman.qos.ch/mailman/listinfo/logback-user
-- Felipe _______________________________________________ Logback-user mailing list Logback-user@qos.ch http://mailman.qos.ch/mailman/listinfo/logback-user

The reason I need to modify MDC properties is that there are a lot of*framework/library generated threads *. Also they are dynamically start and stop. Those threads are *not accessible* to me. When I use log4j/RewriteAppender, I can put properties without care about threads' accessibility like the following. <appender name="stdoutaddprops" class="org.apache.log4j.rewrite.RewriteAppender"> <appender-ref ref="stdout" /> <rewritePolicy class="org.apache.log4j.rewrite.PropertyRewritePolicy"> <param name="properties" value="p1=Hello,p2=World,x1=3.1415,username=${user.name}"/> <!-- here, add some MDC properties --> </rewritePolicy></appender> Is this possible to call MDC.put() for *inaccessible threads*? 2013/7/10 Ralph Goers <rgoers@apache.org>
This will modify the MDC, not just the properties in the logging event, which seems to be what was requested.
Ralph
On Jul 9, 2013, at 7:55 AM, Felipe wrote:
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).
On Tue, Jul 9, 2013 at 10:35 AM, KwonNam Son <kwon37xi@gmail.com> wrote:
Hello,
When I use Log4j, I can add MDC properties to LogginEvent<http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/spi/LoggingEvent.html>by using RewriteAppender<http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/rewrite/RewriteAppender.html>. It's possible because log4j's LoggingEvent is not an interface and it has setProperty()<http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/spi/LoggingEvent.html#setProperty%28java.lang.String,%20java.lang.String%29>method.
Is it possible to add or modify MDC properties dynamically in Logback?
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.
Thanks.
_______________________________________________ Logback-user mailing list Logback-user@qos.ch http://mailman.qos.ch/mailman/listinfo/logback-user
-- Felipe _______________________________________________ Logback-user mailing list Logback-user@qos.ch http://mailman.qos.ch/mailman/listinfo/logback-user
_______________________________________________ Logback-user mailing list Logback-user@qos.ch http://mailman.qos.ch/mailman/listinfo/logback-user
-- * 까먹지말자! http://kwon37xi.egloos.com
participants (3)
-
Felipe
-
KwonNam Son
-
Ralph Goers