在Log4J中限制消息长度 [英] Limit message length in Log4J
本文介绍了在Log4J中限制消息长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发一个使用Log4J进行日志记录的应用程序.有时,该应用程序会创建非常长,> 10000个字符的日志消息.当日志显示在Eclipse的控制台"窗口中时,这会导致性能问题.
I'm working on an application that uses Log4J for logging. Occasionally, the application creates log messages that are very long, > 10000 characters. This causes performance problems when the log is displayed in a Console window in Eclipse.
我想限制最大消息长度,将长消息截断为最大长度.我该如何使用Log4J做到这一点?
I want to limit the maximum message length, truncating long messages to the maximum length. How can I do that with Log4J?
推荐答案
You can use a PatternLayout with a ConversionPattern that has a 'maximum width' format modifier on the message conversion character.
示例:
%r [%t] %-5p %c %x - %.10000m%n
将邮件大小限制为10000个字符.
limits message size to 10000 characters.
这篇关于在Log4J中限制消息长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文