开发者

Why my SiftingAppender stop working when I used a RollingFileAppender?

开发者 https://www.devze.com 2023-02-05 05:43 出处:网络
In my logback config file, I have the following appender that work : <appender name=\"thread_SIFT\" class=\"ch.qos.logback.classic.sift.SiftingAppender\">

In my logback config file, I have the following appender that work :

<appender name="thread_SIFT" class="ch.qos.logback.classic.sift.SiftingAppender">
    <discriminator class="[...]"/>
    <sift>
开发者_运维百科        <appender name="FILE-${threadName}" class="ch.qos.logback.core.FileAppender">
            <file>[...]/${bySecond}/${threadName}.log</file>
            <layout class="ch.qos.logback.classic.PatternLayout">
               <pattern>%date %level %logger{0} - %msg%n</pattern>
            </layout>
        </appender>
    </sift>
</appender>

The file are created correctly. If I replace FileAppender by RollingFileAppender, nothing is created. Why? How can I make it work>

The threadName is set by the discriminator.


The OnConsoleStatusListener is your friend. Just add

<configuration>
  <statusListener class="ch.qos.logback.core.status.OnConsoleStatusListener" />
  .. remainder of your config file
</configuration>

at the beginning of your configuration file to see the errors generated by SiftingAppender.


Seems the property ${bySecond} or any one else is lost inside sift > appender tag.

ERROR in ch.qos.logback.core.joran.spi.Interpreter@23:97 - no applicable
action for [property], current pattern is [[configuration][appender][property]]
[...]/bySecond_IS_UNDEFINED/main.log


There was an error in package name. It seem error under the tag sift are silently ignore. To test, I need to copy the appender outside the sift tag, make sure I have no error and copy it back.


In complement to my comment, you can verify that a file is correctly created using this appender in your sift appender (taken from the Logback Tutorial about RollingFileAppender configuration).

  <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>test.log</file>

    <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
      <fileNamePattern>tests.%i.log.zip</fileNamePattern>
      <minIndex>1</minIndex>
      <maxIndex>3</maxIndex>
    </rollingPolicy>

    <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
      <maxFileSize>5MB</maxFileSize>
    </triggeringPolicy>

    <encoder>
      <pattern>%-4relative [%thread] %-5level %logger{35} - %msg%n</pattern>
    </encoder>
  </appender>
0

精彩评论

暂无评论...
验证码 换一张
取 消