logback的配置文件中可以定义<property>变量,就好像下面代码的“${LOG_HOME}”:
<property name="LOG_HOME" value="c:/log" />
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<FileNamePattern>${LOG_HOME}/myApp.log.%d{yyyy-MM-dd}.log</FileNamePattern>
</rollingPolicy>
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern></pattern>
</layout>
</appender>
想知道,怎么通过Java代码动态的修改LOG_HOME的值?
(小弟现在服务的公司是做银行柜面系统的,希望实现每个柜员号(用户)生成各自的日志文件)
Yes, it is possible. I remember using MDC to save the user name, and then output it to different log files based on the user name.
I don’t know what project you are using?
Yes, please check the official website. There is a chapter introducing this feature.