4

I have my application for which the below entry is done in Log4j properties file.Size based rolling is not working for this application. File does not rollover at 5 MB and the application keeps on logging and making it in GB. In one run approximately 6 MB of log is generated.The application runs multiple times a day.

Can someone help in pointing out where I am doing a mistake?

# SampleApp configuration
log4j.category.com.ibm.hmel.hwmmphdya=INFO, SampleApp  
log4j.additivity.com.ibm.hmel.hwmmphdya=false  
log4j.appender.SampleApp =org.apache.log4j.rolling.RollingFileAppender  
log4j.appender.SampleApp.File=S:/FIH/LOG/SAMPLE_APP_01/SAMPLE_APP_01.log  
log4j.appender.SampleApp.layout=org.apache.log4j.PatternLayout  
log4j.appender.SampleApp.layout.ConversionPattern=%-21d{dd-MMM-yyyy HH:mm:ss} [%t] %-5p %c %x - %m%n  

log4j.appender.SampleApp.RollingPolicy=org.apache.log4j.rolling.FixedWindowRollingPolicy
log4j.appender.SampleApp.RollingPolicy.FileNamePattern=S:/HIF/LOG/SAMPLE_APP_01  /SAMPLE_APP_01.log.%i.zip
log4j.appender.SampleApp.RollingPolicy.MinIndex=1
log4j.appender.SampleApp.RollingPolicy.MaxIndex=10
log4j.appender.SampleApp.TriggeringPolicy=org.apache.log4j.rolling.SizeBasedTriggeringPolicy
log4j.appender.SampleApp.TriggeringPolicy.MaxFileSize=5242880
4

4 回答 4

1

以下对我有用

log4j.rootLogger=TRACE, Roller

log4j.appender.Roller=org.apache.log4j.rolling.RollingFileAppender
log4j.appender.Roller.RollingPolicy=org.apache.log4j.rolling.FixedWindowRollingPolicy  
log4j.appender.Roller.RollingPolicy.maxIndex=13
log4j.appender.Roller.TriggeringPolicy=org.apache.log4j.rolling.SizeBasedTriggeringPolicy  
log4j.appender.Roller.TriggeringPolicy.MaxFileSize=26214400
log4j.appender.Roller.RollingPolicy.FileNamePattern=j_log_%i.log
log4j.appender.Roller.RollingPolicy.ActiveFileName=j_log_0.log
log4j.appender.Roller.layout=org.apache.log4j.PatternLayout
log4j.appender.Roller.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
于 2014-07-11T01:50:35.830 回答
0

尝试将单位添加到您的尺寸

MaxFileSize=5242880KB
于 2013-02-27T07:34:19.153 回答
0

如我所见,您正在使用 lo4j 伴侣附加功能。请确保您使用的是最新的 log4j.jar(1.2.17 版适用于我,我遇到了 1.2.14 版的问题)。

我编写了简单的测试应用程序来重现您的问题:

package com.ibm.hmel.hwmmphdya;
import org.apache.log4j.Logger;

public class Roller {

    private Logger logger = Logger.getLogger(Roller.class);
    private final String FAKE_LOG_LINE = "12345678901234567890123456789012345678901234567890";

    public static void main(String[] args) {
        Roller roller = new Roller();
        roller.logStuff();
    }

    private void logStuff() {
        for (;;) { // ugly loop
            logger.info(FAKE_LOG_LINE);
        }
    }
}

并将以下内容log4j.properties放在类路径中:

log4j.category.com.ibm.hmel.hwmmphdya=INFO, Roller
log4j.additivity.com.ibm.hmel.hwmmphdya=false
log4j.appender.Roller=org.apache.log4j.rolling.RollingFileAppender
log4j.appender.Roller.File=D:/FIH/SAMPLE_APP_01.log
log4j.appender.Roller.layout=org.apache.log4j.PatternLayout
log4j.appender.Roller.layout.ConversionPattern=%-21d{dd-MMM-yyyy HH:mm:ss} [%t] %-5p %c %x - %m%n
log4j.appender.Roller.RollingPolicy=org.apache.log4j.rolling.FixedWindowRollingPolicy
log4j.appender.Roller.RollingPolicy.FileNamePattern=D:/FIH/SAMPLE_APP_01.log.%i.zip 
log4j.appender.Roller.RollingPolicy.MinIndex=1 
log4j.appender.Roller.RollingPolicy.MaxIndex=10 
log4j.appender.Roller.TriggeringPolicy=org.apache.log4j.rolling.SizeBasedTriggeringPolicy
log4j.appender.Roller.TriggeringPolicy.MaxFileSize=5242880

我认为我的结果还可以,这些是我的日志输出目录的内容:

2013-02-27  09:30    <DIR>          .
2013-02-27  09:30    <DIR>          ..
2013-02-27  09:30         4 440 720 SAMPLE_APP_01.log
2013-02-27  09:30         5 242 920 SAMPLE_APP_01.log.1.zip
2013-02-27  09:30         5 242 920 SAMPLE_APP_01.log.2.zip
2013-02-27  09:30         5 242 920 SAMPLE_APP_01.log.3.zip
2013-02-27  09:30         5 242 920 SAMPLE_APP_01.log.4.zip
2013-02-27  09:30         5 242 920 SAMPLE_APP_01.log.5.zip

文件大小“5 242 920”或多或少是配置的大小。

您可以通过提供-Dlog4j.debug系统属性来进一步解决您的问题。

更新: 您可能希望确保伴随的附加库(apache-log4j-extras-1.1.jar)存在于类路径中。

于 2013-02-27T08:51:39.673 回答
0

请检查您是否已包含apache-log4j-extras.jar并使用log4j-1.2.16.jar或至少高于 2.17 版本。这是可以使用的示例 log4j.properties。

    #Worked with 2.17 version
    #make log files rotate based on size and zip old rotated
    log4j.rootLogger=INFO, loggerId
    log4j.appender.loggerId=org.apache.log4j.rolling.RollingFileAppender
    log4j.appender.loggerId.rollingPolicy=org.apache.log4j.rolling.FixedWindowRollingPolicy
    log4j.appender.loggerId.rollingPolicy.maxIndex=5
    log4j.appender.loggerId.triggeringPolicy=org.apache.log4j.rolling.SizeBasedTriggeringPolicy
    log4j.appender.loggerId.triggeringPolicy.MaxFileSize=10000000
    log4j.appender.loggerId.rollingPolicy.FileNamePattern=worker-%i.log.gz
    log4j.appender.loggerId.rollingPolicy.ActiveFileName=worker.log
    log4j.appender.loggerId.layout=org.apache.log4j.PatternLayout
    log4j.appender.loggerId.layout.ConversionPattern=%d [%t] %-5p (%F:%L) - %m%n

有关房产的更多详细信息,请查看此处

于 2016-10-26T13:26:53.333 回答