[logback-user] Is it possible to acces MDC values as properties?

Stefan Eder stefan.eder at ebuconnect.de
Sun Feb 26 01:18:03 CET 2012


Hello Ralph,

I know that the sifting appender can route data to different log files, 
the sifting appender wouldn't make much sense without that feature and 
this exactly my use case.
But AFAIK only the MDC key that is used as discriminator is referable as 
a property variable in the file name pattern and I want to refer to 
another MDC key.
If there is a way to refere to arbitrary MDC values using their MDC keys 
as property names or whatever to do something like:
<file>logs/${mdc.someKey}/${mdc.someOtherKey}.log</file>
Then I would like to know how.

Regards,
Stefan



On 22.02.2012 15:54, Ralph Goers wrote:
> I'm not understanding what you are doing. There are ways to do what you want without resorting to what you have below. For example, the sifting appender will route data to different log files.
>
> When Logback reconfigures it removes all the filters and appenders that have been configured and for a time the loggers have no configuration at all. I then uses your new configuration to add back the filters and appenders and have the loggers reference them. Thus, you will lose everything you configured programmatically when you update logback.xml.
>
> Ralph
>
> On Feb 22, 2012, at 5:17 AM, Stefan Eder wrote:
>
>> Hi,
>>
>> applies to Logback classic 1.0.0.
>>
>> Is it possible to acces MDC values as properties like this:
>> <file>${catalina.base}/logs/exchanges/${breadcrumbId}-gsem.log</file>
>> <encoder>
>> <pattern>...</pattern>
>> </encoder>
>> where 'breadcrumbId' is mapped in the MDC.
>>
>> The above example produces a file named breadcrumbId_IS_UNDEFINED-gsem.log.
>> The snippet is used in a sifting appender, but 'breadcrumbId' is not the descriminator.
>>
>> Do I have to use another notation or do I have to implement ch.qos.logback.core.spi.PropertyDefiner?
>>
>> Thanks,
>> Stefan
>>
>>
>> _______________________________________________
>> Logback-user mailing list
>> Logback-user at qos.ch
>> http://mailman.qos.ch/mailman/listinfo/logback-user
>
> _______________________________________________
> Logback-user mailing list
> Logback-user at qos.ch
> http://mailman.qos.ch/mailman/listinfo/logback-user
>
>


More information about the Logback-user mailing list