Logback 文件错误:[滚动策略]没有适用的操作,当前模式为 [[配置][追加器][滚动策略]]

2022-09-03 17:18:00

我正在使用akka登录将日志写入文件,一切都很好,直到我的日志文件停止写入日志,也许它已满,所以我阅读了abou滚动策略,所以我可以创建其他文件,但我最终有很多错误,这是我的logback文件.xml文件

<configuration>
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
  <File>/media/sara/682AA7A32AA76D2E/study/ifkaarproject/articateInScala/log/akka.log</File>
      <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
      <fileNamePattern>/media/sara/682AA7A32AA76D2E/study/ifkaarproject/articateInScala/log/akka.%i.log</fileNamePattern>
      <minIndex>1</minIndex>
      <maxIndex>3</maxIndex>
    </rollingPolicy>

   <triggeringPolicy class="com.bigbasket.dapp.utilities.SizeBasedTriggeringPolicy">
        <maxFileSize>5MB</maxFileSize>
    </triggeringPolicy>

     <encoder>
          <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%-5level] %logger{0} %X{akkaSource} %msg%n</pattern>
         </encoder>
   </appender>

    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">

    <encoder>
      <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %logger{0} %X{akkaSource} -%msg%n</pattern>
    </encoder>

  </appender>

   <root level="info">
   <appender-ref ref="FILE" />
    <appender-ref ref="STDOUT"/>

   </root>
</configuration>

当我在sbt中运行我的应用程序时,以下消息打印出来

15:29:30,350 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy]
15:29:30,350 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml]
15:29:30,351 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback.xml] at [file:/media/sara/682AA7A32AA76D2E/study/ifkaarproject/articateInScala/target/scala-2.11/classes/logback.xml]
15:29:30,594 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - debug attribute not set
15:29:30,595 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.FileAppender]
15:29:30,605 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [FILE]
15:29:30,675 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@4:83 - no applicable action for [rollingPolicy], current pattern is [[configuration][appender][rollingPolicy]]
15:29:30,676 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@5:24 - no applicable action for [fileNamePattern], current pattern is [[configuration][appender][rollingPolicy][fileNamePattern]]
15:29:30,676 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@6:17 - no applicable action for [minIndex], current pattern is [[configuration][appender][rollingPolicy][minIndex]]
15:29:30,676 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@7:17 - no applicable action for [maxIndex], current pattern is [[configuration][appender][rollingPolicy][maxIndex]]
15:29:30,677 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@10:85 - no applicable action for [triggeringPolicy], current pattern is [[configuration][appender][triggeringPolicy]]
15:29:30,677 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@11:22 - no applicable action for [maxFileSize], current pattern is [[configuration][appender][triggeringPolicy][maxFileSize]]
15:29:30,678 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
15:29:30,728 |-INFO in ch.qos.logback.core.FileAppender[FILE] - File property is set to [/media/sara/682AA7A32AA76D2E/study/ifkaarproject/articateInScala/log/akka.log]
15:29:30,729 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
15:29:30,731 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [STDOUT]
15:29:30,734 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
15:29:30,735 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to INFO
15:29:30,735 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [FILE] to Logger[ROOT]
15:29:30,736 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [STDOUT] to Logger[ROOT]
15:29:30,736 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
15:29:30,738 |-INFO in ch.qos.logback.classic.joran.JoranConfigurator@6f2bba4f - Registering current configuration as safe fallback point

在此之前,一切都很好.log akka文件没有容量,所以我别无选择地使用这个滚动政策的东西,请帮助我<rollingPolicy> <triggeringPolicy>


答案 1

您需要使用 类型的记录器,而不是 ,如下所示:RollingFileAppenderFileAppender

<configuration>
    <!-- this is the important line -->
    <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <File>/media/sara/682AA7A32AA76D2E/study/ifkaarproject/articateInScala/log/akka.log</File>
        <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
            <fileNamePattern>/media/sara/682AA7A32AA76D2E/study/ifkaarproject/articateInScala/log/akka.%i.log</fileNamePattern>
            <minIndex>1</minIndex>
            <maxIndex>3</maxIndex>
        </rollingPolicy>
        <triggeringPolicy class="com.bigbasket.dapp.utilities.SizeBasedTriggeringPolicy">
            <maxFileSize>5MB</maxFileSize>
        </triggeringPolicy>
        <encoder>
            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%-5level] %logger{0} %X{akkaSource} %msg%n</pattern>
        </encoder>
    </appender>
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %logger{0} %X{akkaSource} -%msg%n</pattern>
        </encoder>
    </appender>
    <root level="info">
        <appender-ref ref="FILE" />
        <appender-ref ref="STDOUT" />
    </root>
</configuration>

答案 2

我在弹簧靴中遇到了略有不同的问题:

ERROR in ch.qos.logback.core.joran.spi.Interpreter@90:29 - no applicable action for [priority], current ElementPath  is [[configuration][root][priority]]

我修复了它从logback.xml文件中删除标签的问题。<priority></priority><root> level

<root level="INFO">
        <appender-ref ref="stdout" />
        <appender-ref ref="file" />
         <priority level="INFO"/> // removed this line
    </root>

推荐