search

Home  >  Q&A  >  body text

java - Logback能否根据用户动态生成不同的User日志文件?

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

大家讲道理大家讲道理2766 days ago404

reply all(3)I'll reply

  • 大家讲道理

    大家讲道理2017-04-18 09:26:21

    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.

    reply
    0
  • 天蓬老师

    天蓬老师2017-04-18 09:26:21

    I don’t know what project you are using?

    reply
    0
  • PHPz

    PHPz2017-04-18 09:26:21

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

    reply
    0
  • Cancelreply