本文介绍了log4j.xml中用于根据时间和大小旋转日志的配置是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果有办法根据时间和大小轮换日志文件,请告诉我。

Kindly let me know if there is a way to rotate the logfiles based on time as well as size.

日志文件必须采用logfilename格式.log.date根据时间发生翻转。

The log file is required to be in a format logfilename.log.date when the roll over happens based on time.

推荐答案

如果你想根据时间进行轮换可能是最好的做法。您可以根据您的配置获得年度,月度,小时等日志。

If you want to do the rotation based on time DailyRollingFileAppender probably is the best practice. You can have yearly, monthly, hourly etc logs based on your configuration.

如果您想要基于大小的轮换可能非常有用。

If you want size based rotation RollingFileAppender could be very useful.

此外,如果你想同时使用时间和大小我建议你看看 TimeAndSizeRollingAppender ,根据Apache 2.0许可免费,该许可声称提供DailyRollingFileAppender和RollingFileAppender的完整功能。

Furthermore, if you want to use both time and size at the same time I would suggest you to take a look at TimeAndSizeRollingAppender, free under the Apache 2.0 license, which claims to be providing full features of both DailyRollingFileAppender and RollingFileAppender.

这篇关于log4j.xml中用于根据时间和大小旋转日志的配置是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 04:34