xxfhf 2015-01-21 10:34 采纳率: 0%
浏览 6911

logback日志数量修改问题

现在需要将logback的最大日志数量提高到40个,由于logback内部最大只支持20个,设置超过20后也只输出20个文件。

重写FixedWindowRollingPolicy类如下:

package com.logback.test;
import ch.qos.logback.core.rolling.FixedWindowRollingPolicy;

public class CustomFixedWindowRollingPolicy extends FixedWindowRollingPolicy {

private static int MAX_WINDOW_SIZE = 500;

@Override
protected int getMaxWindowSize() {
    return MAX_WINDOW_SIZE;
}

}

logback.xml配置如下:

<appender name="realMasterAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <File>${log.home}/real.log</File>
    <rollingPolicy class="com.logback.test.CustomFixedWindowRollingPolicy">
        <fileNamePattern>${log.home}/real.log.%i</fileNamePattern>
        <minIndex>1</minIndex>
        <maxIndex>100</maxIndex>
    </rollingPolicy>
    <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
        <maxFileSize>40MB</maxFileSize>
    </triggeringPolicy>
    <encoder>
        <pattern>%date %level [%file : %line] %msg%n</pattern>
    </encoder>
    <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
        <level>DEBUG</level>
    </filter>
</appender>


运行后后台报错如下:
17:32:44,585 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property

17:32:44,632 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.rolling.RollingFileAppender]
17:32:44,632 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [infoAppender]
17:32:44,632 |-ERROR in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Could not create component [rollingPolicy] of type [com.logback.test.CustomFixedWindowRollingPolicy] java.lang.ClassNotFoundException: com.logback.test.CustomFixedWindowRollingPolicy
at java.lang.ClassNotFoundException: com.logback.test.CustomFixedWindowRollingPolicy
at at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:494)
at at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:410)
at at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:398)
at at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:105)
at at java.lang.ClassLoader.loadClass(Unknown Source)
at at ch.qos.logback.core.util.Loader.loadClass(Loader.java:124)
at at ch.qos.logback.core.joran.action.NestedComplexPropertyIA.begin(NestedComplexPropertyIA.java:100)
at at ch.qos.logback.core.joran.spi.Interpreter.callBeginAction(Interpreter.java:275)
at at ch.qos.logback.core.joran.spi.Interpreter.startElement(Interpreter.java:147)
at at ch.qos.logback.core.joran.spi.Interpreter.startElement(Interpreter.java:129)
at at ch.qos.logback.core.joran.spi.EventPlayer.play(EventPlayer.java:50)

求解啊!
  • 写回答

1条回答 默认 最新

  • Bairrfhoinn 2016-06-24 02:38
    关注

    我按照你的思路做了壹次,在我的机器上没有发现任何问题,难道是你的 Logback 版本太低导致这個问题的?我的环境下使用的是logback 1.1.7,看了下这個帖子的发布时间是2005年01月21日,那时候的 logback 版本应该是比较低的,后继的版本修复了类似问题也说不定。

    评论

报告相同问题?

悬赏问题

  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建