java Log4j 附加程序大小

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13951234/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 14:33:00  来源:igfitidea点击:

Log4j appender size

javalogginglog4j

提问by Muhammad Imran Tariq

My appender size was set to MB in log4j appneder but when I changed it to KB's It did not work. Can I set log4j appender size in KB's.

我的 appender 大小在 log4j appneder 中设置为 MB,但是当我将其更改为 KB 时,它不起作用。我可以以 KB 为单位设置 log4j appender 大小吗?

Like

喜欢

log4j.appender.processAppender.MaxFileSize=20KB

If yes then is there need to add another property? My file looks like:

如果是,那么是否需要添加另一个属性?我的文件看起来像:

log4j.rootLogger=DEBUG,FileAppender
log4j.logger.process=debug, processAppender
log4j.appender.processAppender=org.apache.log4j.RollingFileAppender 
log4j.appender.processAppender.File=D:/logs/process.log

log4j.appender.processAppender.Append=true
log4j.appender.processAppender.MaxFileSize=20KB
log4j.appender.processAppender.MaxBackupIndex=3
log4j.appender.processAppender.layout=org.apache.log4j.PatternLayout

log4j.appender.processAppender.layout.ConversionPattern=%d %-5p - %m%n

回答by ved

I've used below code

我使用了下面的代码

    log4j.appender.file=org.apache.log4j.RollingFileAppender
    log4j.appender.file.File=AgentWorkstation.log

    log4j.appender.file.Append=true
    log4j.appender.A1.MaxFileSize=10KB

    log4j.appender.A2.MaxBackupIndex=3

    log4j.appender.file.layout=org.apache.log4j.PatternLayout
    log4j.appender.file.layout.ConversionPattern=%d{dd MMM yyyy HH:mm:ss,SSS}
    %-5p (%C{1}:%L) - %m\n

It worked perfectly for me

它非常适合我

回答by Subhrajyoti Majumder

Set the maximum size that the output file is allowed to reach before being rolled over to backup files. In configuration files, the MaxFileSize option takes an long integer in the range 0 - 2^63. You can specify the value with the suffixes "KB", "MB" or "GB" so that the integer is interpreted being expressed respectively in kilobytes, megabytes or gigabytes. For example, the value "10KB" will be interpreted as 10240.

设置输出文件在滚动到备份文件之前允许达到的最大大小。在配置文件中,MaxFileSize 选项采用 0 - 2^63 范围内的长整数。您可以指定带有后缀“KB”、“MB”或“GB”的值,以便将整数解释为分别以千字节、兆字节或千兆字节表示。例如,值“10KB”将被解释为 10240。

Reference

参考

回答by Parvin Gasimzade

Yes you can set KB as a unit and your configuration seems like correct. This is the explanation from the IBM's webpage.

是的,您可以将 KB 设置为一个单位,并且您的配置似乎是正确的。这是来自IBM 网页的解释。

Specifies the maximum file size that the log file is allowed to take up on disk.

Default size is 100 MB.

Uses the following format:

log4j.appender.S1.MaxFileSize=SizeUnits

where:

Size is the numeric value for the file size. Units can be KB, MB, or GB. For example, to limit the log file size to 10 MB, enter the following:

log4j.appender.S1.MaxFileSize=10 MB

If the MaxBackupIndex parameter is set to 1 or greater, then the logging process automatically creates a backup file when the log file reaches the MaxFileSize. The total number of backup files is determined by MaxBackupIndex option.

指定允许日志文件在磁盘上占用的最大文件大小。

默认大小为 100 MB。

使用以下格式:

log4j.appender.S1.MaxFileSize=SizeUnits

在哪里:

大小是文件大小的数值。单位可以是 KB、MB 或 GB。例如,要将日志文件大小限制为 10 MB,请输入以下内容:

log4j.appender.S1.MaxFileSize=10 MB

如果 MaxBackupIndex 参数设置为 1 或更大,那么当日志文件达到 MaxFileSize 时,日志记录过程会自动创建一个备份文件。备份文件的总数由 MaxBackupIndex 选项决定。

回答by Buddhika Lakshan

You should change 3 property under the Appender.

您应该更改 Appender 下的 3 个属性。

    log4j.appender.CARBON_LOGFILE.Append=true
    log4j.appender.CARBON_LOGFILE.MaxFileSize=10MB
    log4j.appender.CARBON_LOGFILE.MaxBackupIndex=20