如何让log4j打印消息来源?

时间:2014-11-24 09:57:19

标签: java logging log4j

有没有办法让Log4j-outputs包含消息的来源? 通过log4j.properties进行了以下配置(已经移交给我......):

log4j.rootCategory=INFO, A1
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%-5p - %m%n

无法打印出发送该消息的类的非常重要的细节,而现在我真的需要那些信息!

Layna

2 个答案:

答案 0 :(得分:2)

请参阅Conversion Pattern Layout

例如,您可以使用ConversionPattern =%d {ABSOLUTE}%5p%t%c {1}:%M:%L - %m%n

答案 1 :(得分:0)

If you use the %C notation, you can see the package and the class name of the log origin.

So, you can use:

log4j.rootCategory=INFO, A1
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%-5p - %m%n - %C