在我的logback配置文件中,我有以下适用的appender:
<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>
正确创建文件。如果我用RollingFileAppender替换FileAppender,则不会创建任何内容。为什么?我怎样才能使它工作&gt;
threadName由鉴别器设置。
答案 0 :(得分:4)
OnConsoleStatusListener是你的朋友。只需添加
<configuration>
<statusListener class="ch.qos.logback.core.status.OnConsoleStatusListener" />
.. remainder of your config file
</configuration>
在配置文件的开头,以查看SiftingAppender
生成的错误。
答案 1 :(得分:2)
似乎属性${bySecond}
或sift > appender
标记内的任何其他内容丢失。
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
答案 2 :(得分:0)
包名中有错误。标签sift下的似乎错误是默默无视。为了测试,我需要在sift标签之外复制appender,确保我没有错误并将其复制回来。
答案 3 :(得分:-1)
作为对我的评论的补充,您可以验证在sift appender中使用此appender正确创建了一个文件(取自关于RollingFileAppender配置的Logback教程)。
<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>