java Log4J 不在日志文件条目之间添加换行符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1806378/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Log4J not adding newlines between logfile entries
提问by ssakl
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:
我刚开始使用 log4j。它读取我的属性文件并实际记录事件没有问题,但它似乎将所有内容附加到同一行的末尾。我的属性文件如下所示:
# 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
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.
以上是从log4j the Complete Manual 中的示例修改而来的。我徒劳地翻阅了这本书和谷歌,以列出所有选项的含义,但无济于事。
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 版本 1.2.15 与 Java 6 一起使用。我该怎么做才能将每个日志条目放在单独的行上,在哪里可以找到所有选项的列表以及它们的作用?
回答by jitter
Replace
代替
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
Same for A2 + there remove the %after the n %m%n%-> m%n
与 A2 + 相同,删除%n %m%n%->m%n
Basically you seem to have a newline after the -character in your ConversionPatternlines. That would explain why the newline isn't output (%n--> outputs platform dependend newline character)
基本上你似乎-在你的ConversionPattern行中的字符后面有一个换行符。这将解释为什么不输出换行符(%n--> 输出平台相关换行符)
Btw. if you want to know what the options mean
顺便提一句。如果您想知道选项的含义
回答by Carl Smotricz
Are those %m%non the same line as the rest? If not, that would explain it.
那些%m%n和其他人在同一条线上吗?如果没有,那就可以解释了。
Oh, and for the 2nd appender, you have a % after %n. That doesn't look right either.
哦,对于第二个附加程序,您在%n. 这看起来也不对。

