日期:2014-05-17 浏览次数:20798 次
MDC.put("userid", "123456789");
MDC.put("departid", "组织部");
<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
<!-- 控制台输出日志 -->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>%d{yyyy-MM-dd HH:mm:ss}, %p, %c, %t, %r, %ex, %F, %L, %C{1},
%M : %m%n</pattern>
</layout>
</appender>
<!-- 按用户输出日志 -->
<appender name="SIFT" class="ch.qos.logback.classic.sift.SiftingAppender">
<discriminator>
<Key>userid</Key>
<Key>departid</Key>
<DefaultValue>unknown</DefaultValue>
</discriminator>
<sift>
<appender name="FILE-${userid}" class="ch.qos.logback.core.FileAppender">
<File>log/${departid}/${userid}.log</File>
<Append>false</Append>
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>%d [%thread] %level %mdc %logger{35} - %msg%n</Pattern>
</layout>
</appender>
</sift>
</appender>
<root level="ALL">
<appender-ref ref="STDOUT" />
<appender-ref ref="SIFT" />
</root>
</configuration>