How to write different logs in different files with log4j2 (MDC in xml)?

前端 未结 1 733
借酒劲吻你
借酒劲吻你 2020-12-03 20:01

Now I\'m using structure like this: Appender:



        
相关标签:
1条回答
  • 2020-12-03 20:48

    Take a look at RoutingAppender. Maybe this can get you started:

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration status="DEBUG" name="MyApp" packages="">
      <appenders>
        <Routing name="Routing">
          <Routes pattern="$${ctx:USERNAME}">
            <Route>
              <RollingFile name="user.log" append="true" fileName="users/${ctx:USERNAME}.txt"
                 filePattern="users/archive/${ctx:USERNAME}-%d{MM-dd-yyyy}-%i.txt.gz">
                <PatternLayout>
                  <pattern>%d{ISO8601} [%t] %p %c %L - %m%n</pattern>
                </PatternLayout>
                <Policies>
                  <TimeBasedTriggeringPolicy/>
                  <SizeBasedTriggeringPolicy size="50 MB"/>
                </Policies>
              </RollingFile>
            </Route>
          </Routes>
        </Routing>
      </appenders>
    
      <loggers>
        <root level="TRACE">
          <appender-ref ref="Routing" level="DEBUG" />
        </root>
      </loggers>
    </configuration>
    
    0 讨论(0)
提交回复
热议问题