I am currently trying to generate a log path using the discriminator supported by logback.
When creating a log path, I am using org.slf4j.MDC to create the log path by putting the value in the key I specified in the log path.
Below is the source code that I actually save as MDC.
LogServeice.java
MDC.put("key1", "test1";
MDC.put("key2", "test2");
MDC.clear();
Below this is the file source code actually set in logback-spring.xml.
logback-spring.xml
<appender name="ApiRollingFile" class="ch.qos.logback.classic.sift.SiftingAppender">
<discriminator>
<key>key1</key>
<defaultValue>unknown</defaultValue>
</discriminator>
<discriminator>
<key>key2</key>
<defaultValue>unknown</defaultValue>
</discriminator>
<sift>
<appender name="LOG_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>%d{yyyyMMddHH}/${key1}/${key2}/${API_FILENAME}.log
</fileNamePattern>
</rollingPolicy>
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>%m%n</pattern>
</layout>
</encoder>
</appender>
</sift>
</appender>
I used it like this
The value of key1 is not recognized.
key1_IS_UNDEFINED A folder is created like this.
However, the folder for key2 is created fine.
Can I find out why this is the case?
Isn't it possible to use multiple key values in MDC?
Is there a way to use multiple of them?
Below is the source code that I actually save as MDC.