如何减少日志大小 [英] How to reduce logs size

查看:53
本文介绍了如何减少日志大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我从事的每个项目中,始终存在日志文件过大的问题. 一个现成的快速解决方案是使用Log4j RollingFileAppender并设置允许的最大大小. 但是,在某些情况下,相同的异常反复发生,很快有人达到最大值,然后有人手动干预.在那种情况下,由于采用滚动策略,您最终将丢失有关在异常发生之前发生的重要事件的信息. 有人可以建议解决此问题的方法吗?

In every project I've been working on there's always been the issue of log files becoming too large. A quick off the shelf solution was to use the Log4j RollingFileAppender and set the maximum size allowed. However there are situations when the same exception happens repeatedly reaching the maximum size very quickly, before somebody manually intervenes. In that scenario because of the rolling policy you end up losing information of important events that happened just before the exception. Can anybody suggest a fix for this issue?

P.S.我能想到的是保存到目前为止已发生的Exceptions的缓存,这样,当再次发生相同的异常时,我不会记录大量的stacktrace行.尽管如此,我仍然认为这一定是一个众所周知的问题,我不想重蹈覆辙.

P.S. Something I can think of is to hold a cache of the Exceptions happened so far, so that when the same Exception re-occurs I don't log tons of stacktrace lines. Still I think this must be a well-known issue and I don't want to reinvent the wheel.

推荐答案

使用"Rolling File Appender"达到指定大小后,使用Log4J功能压缩日志文件. 1MB文件的压缩大小约为85KB. 为此,请指定触发策略以基于大小进行zip,并在滚动策略中指定zip文件.
让我知道您是否需要信息.

Use Log4J feature to zip the log file after a specified size is reached using "Rolling File Appender". Zips are around 85KB for a 1MB file. For this specify the trigger policy to zip based on size and specify the zip file in the rolling policy.
Let me know if you need for info.

这篇关于如何减少日志大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆