java - Logback能否根据用户动态生成不同的User日志文件?
大家讲道理
大家讲道理 2017-04-18 09:24:21
0
3
401

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的值?
(小弟现在服务的公司是做银行柜面系统的,希望实现每个柜员号(用户)生成各自的日志文件)

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(3)
大家讲道理

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.

Peter_Zhu

I don’t know what project you are using?

PHPzhong

Yes, please check the official website. There is a chapter introducing this feature.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template