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 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序