i have to generate logs for each "user" of our web application. For that, we used a SiftingAppender with a Discriminator.
<appender name="SEPARATED" class="ch.qos.logback.classic.sift.SiftingAppender">
<discriminator>
<key>userid</key>
<defaultValue>unknown</defaultValue>
</discriminator>
<sift>
<appender name="MYAPPLI_${userid}_SEPARATED" class="ch.qos.logback.core.FileAppender">
<file>${LOG}/MYAPPLI/MYAPPLI_${userid}_SEPARATED.log</file>
<append>true</append>
<encoder>
<pattern><%d{yyyy-MM-dd HH:mm:ss}> | %.-1level | %msg %throwable{5}%n</pattern>
</encoder>
</appender>
</sift>
</appender>
We added a servlet web filter in order to add the user from session to the MDC, and to remove it after...
But, we have some problems. We have some cases (why?) where "userid" variable is undefined, so logs appears with this name : MYAPPLI_unknown_SEPARATED.log.
Is the MDC a singleton of the web application ? Or is it in a scope session ?
In reality, i have to generate 2 logs / user session. So i have a second SiftingAppender with the same discriminator, and a filter (Thresholdfilter) cause the second log should be the same with a different level of trace. Is it the good way to do that ?
Thank you.