问题描述
我正在研究使用log4j进行记录的应用程序.有时,该应用程序会创建非常长的日志消息,> 10000个字符.当日志显示在Eclipse的控制台窗口中时,这会导致性能问题.
我想限制最大消息长度,将长消息截断至最大长度.我该如何使用log4j?
推荐答案
您可以使用带有在消息转换字符上具有"最大宽度"格式修饰符的转换模式.
示例:
%r [%t] %-5p %c %x - %.10000m%n
将消息大小限制为10000个字符.
其他推荐答案
如果有人正在寻找最大宽度,那是删除最后一个字符,而不是第一个(就像我一样),这是一个示例:
%r [%t] %-5p %c %x - %-0.-10000m%n
将消息大小限制为10000个字符,并删除末尾的所有内容.
来源: -926
问题描述
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?
推荐答案
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.
其他推荐答案
If someone is looking for a maximum width, that is removing the last characters and not the first (like i did) here is an example:
%r [%t] %-5p %c %x - %-0.-10000m%n
limits the message size to 10000 characters and removes everything on the end that is longer.