Log4J没有在日志文件条目之间添加换行符 [英] Log4J not adding newlines between logfile entries

查看:1981
本文介绍了Log4J没有在日志文件条目之间添加换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始使用log4j。我在阅读我的属性文件并实际记录事件时没有问题,但似乎是将所有内容追加到同一行的末尾。我的属性文件如下所示:

I am just starting with log4j. I don't have a problem with it reading my properties file and actually logging events, but it seems to be appending everything to the end of the same line. My properties file looks like this:

# A1 is set to be a ConsoleAppender.
log4j.appender.A1=org.apache.log4j.ConsoleAppender

# A2 is set to be a ConsoleAppender.
log4j.appender.A2=org.apache.log4j.FileAppender

# A1 uses PatternLayout.
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x -
%m%n

# A2 uses PatternLayout.
log4j.appender.A2.layout=org.apache.log4j.PatternLayout
log4j.appender.A2.layout.ConversionPattern=%-4r [%t] %-5p %c %x -
%m%n%

log4j.appender.A2.file=grocerylister.log

以上是从 log4j完整手册中的示例进行了修改。我毫不费力地浏览了这本书和谷歌,列出了所有选项的含义,但无济于事。

The above was modified from an example in log4j the Complete Manual. I have fruitlessly looked through the book and Google to get a listing of what all the options mean, to no avail.

我正在使用带有Java 6的log4j 1.2.15版。如何在单独的行中获取每个日志条目以及在哪里可以找到列表所有选项是什么以及他们做什么?

I'm using log4j version 1.2.15 with Java 6. What can I do to get each log entry on a separate line and where can I find a list of what all the options are and what they do?

推荐答案

替换

log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x -
%m%n

with

log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n

A2 +同样在n %m%n% - > <$之后删除 c $ c> m%n

Same for A2 + there remove the % after the n %m%n% -> m%n

基本上你似乎在之后有一个换行符 - ConversionPattern 行中的字符。这可以解释为什么不输出换行符(%n - >输出平台依赖换行符)

Basically you seem to have a newline after the - character in your ConversionPattern lines. That would explain why the newline isn't output (%n --> outputs platform dependend newline character)

顺便说一句。如果你想知道这些选项意味着什么

Btw. if you want to know what the options mean

javadoc:PatternLayout

这篇关于Log4J没有在日志文件条目之间添加换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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