[logback-user] MDC and env-entry

José Juan Montiel josejuan.montiel at eurobits.es
Tue Mar 1 13:54:35 CET 2011


Hi,

You could easyly write your own discriminator class combining
> JNDIBasedContextDiscriminator and MDCBasedDiscriminator. Here is an
> example:
>
> public class CombinedDiscriminator extends ContextAwareBase implements
>     Discriminator<ILoggingEvent> {
>
>  private String defaultMDCVal = "default";
>
>   public String getDiscriminatingValue(ILoggingEvent event) {
>     String mdcValue = defaultMDCVal;
>     Map<String, String> mdcMap = event.getMdc();
>     if (mdcMap != null) {
>       mdcValue = mdcMap.get(key);
>     }
>     String contextName =  event.getLoggerContextVO().getName();
>     return contextName + mdcValue;
>   }
>   ..etc
> }
>
>
Thanks for reply, i started to implement, but i noticed that maybe i don't
explain well, i dont need "sumValue = contextName + mdcValue" value to use
in <FileNamePattern>${newValue}.log</FileNamePattern>

That i really need is two values... contextName and mdcValue...

The aprox, maybe something like
<FileNamePattern>${newValue.substring(0,x)}/${newValue.substring(x,n)}.log</FileNamePattern>

or something like

<appender ... class="ch.qos.logback.classic.sift.SiftingAppender">
    <discriminator
class="ch.qos.logback.classic.sift.JNDIBasedContextDiscriminator">
    ...
        <sift>
            <appender ...
class="ch.qos.logback.classic.sift.SiftingAppender">
                <discriminator>
                ...
                <sift>
                    <appender
class="ch.qos.logback.core.rolling.RollingFileAppender">

SiftingAppender inside SiftingAppender to use MDC and contextName.

Any suggestion?

And thanks again.

-- 
Jose Juan Montiel Martinez
Eurobits Technologies
Calle Musgo 3, 1ª Planta
28023 Madrid
T +34-917080300
F +34-913077480
josejuan.montiel at eurobits.es
http://www.eurobits.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://qos.ch/pipermail/logback-user/attachments/20110301/56ef23b7/attachment.html>


More information about the Logback-user mailing list