简体   繁体   English

log4j:轮换日志,当其大小超过定义的阈值时

[英]log4j: rotate log, when it's size exceeds defined threshold

We have recently encountered a problem: if external service fails, logs easily become flooded with similar data indicating a problem. 我们最近遇到了一个问题:如果外部服务失败,日志很容易充斥着指示问题的类似数据。 In logback problem was solved easily: I've set log size threshold, after which log files were rolled over and zipped. logback中,问题很容易解决:我设置了日志大小阈值,然后将日志文件翻转并压缩。

Is there a similar feature, when using log4j? 使用log4j时是否有类似的功能? I need to have a support for both daily rollover and size-threshold rollover. 我需要同时支持每日翻转和大小阈值翻转。

Hava a look at RollingFileAppender . 让我们看看RollingFileAppender There is an example that you can base on. 您可以基于一个示例。 An appender for daily rolling is included. 包括每日滚动的附加程序。 You can extend it if you need an additional size threshold, or use the TimeAndSizeRollingAppender from Simon Park. 如果需要其他大小阈值,则可以扩展它,或者使用Simon Park的TimeAndSizeRollingAppender

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM