简体   繁体   中英

How to move Child Package logs to different log File in logback?

    <?xml version="1.0" encoding="UTF-8"?>
<configuration>

<appender name="appLog" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!--See also http://logback.qos.ch/manual/appenders.html#RollingFileAppender-->
<File>${appLogFile}</File>
<encoder>
   <Pattern>%d{dd-MM-yy HH:mm:ss.SSS}\t%X{reqId}\t%thread\t%level\t%logger{36}\t%M\t%line\t%msg%n</Pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
   <fileNamePattern>${appLogFile}.%i</fileNamePattern>
   <minIndex>1</minIndex>
   <maxIndex>3</maxIndex>
</rollingPolicy>
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
   <maxFileSize>50MB</maxFileSize>
</triggeringPolicy>
</appender>

<appender name="REPORT-XYZ-LOG-APPENDER"
class="ch.qos.logback.core.rolling.RollingFileAppender">

<file>${appLogFile}.reports_xyz.log</file>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
  <Pattern>%d{dd-MM-yy HH:mm:ss.SSS}\t%X{reqId}\t%23thread\t%-5level\t%-38logger{36}\t%-25M\t%4line\t%msg%n</Pattern>
</encoder>

<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
  <!-- rollover daily -->
  <fileNamePattern>${appLogFile}.reports_xyz.log.%d{yyyy-MM-dd}.%i</fileNamePattern>
  <timeBasedFileNamingAndTriggeringPolicy   class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
    <maxFileSize>10MB</maxFileSize>
  </timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
</appender>

<appender name="REPORT-LOG-APPENDER"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${appLogFile}.reports.log</file>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
  <Pattern>
            %d{dd-MM-yy HH:mm:ss.SSS}\t%X{reqId}\t%thread\t%level\t%logger{36}\t%M\t%line\t%msg%n
        </Pattern>
</encoder>

<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
  <!-- rollover daily -->
  <fileNamePattern>${appLogFile}.reports.log.%d{yyyy-MM-dd}.%i</fileNamePattern>
  <timeBasedFileNamingAndTriggeringPolicy   class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
    <maxFileSize>10MB</maxFileSize>
  </timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>

</appender>

<logger name="com.xyz.a.b.c" level="INFO" additivity="false">
<appender-ref ref="REPORT-XYZ-LOG-APPENDER" />
</logger>

<logger name="com.xyz" level="INFO" additivity="false">
  <appender-ref ref="appLog"/>
</logger>

<root level="INFO">
<appender-ref ref="REPORT-LOG-APPENDER" />
</root>

</configuration>

I want to move the logs for package "com.xyz.abc" to different file in place of where package "com.xyz" logs are going. But after using above logback.xml file, logs are still going to ${appLogFile} ( appLogFile is system Property and have absolute file path) for both parent as well as child packages. Can someone help me what i am doing wrong here ?

I want to move logs for com.xyz.abc --> File1 com.xyz --> File2

I got the answer. it was my mistake only. changed the logback.xml file to move it

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM