Limit message length in Log4J

 ̄綄美尐妖づ 提交于 2019-12-20 02:48:11

问题


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.

I want to limit the maximum message length, truncating long messages to the maximum length. How can I do that with Log4J?


回答1:


You can use a PatternLayout with a ConversionPattern that has a 'maximum width' format modifier on the message conversion character.

Example:

%r [%t] %-5p %c %x - %.10000m%n

limits message size to 10000 characters.



来源:https://stackoverflow.com/questions/34066735/limit-message-length-in-log4j

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!