当你写是否可以在log4j中为stacktrace的每一行加前缀?
logger.error("message", exception);
log4j的生产信息和完整的堆栈跟踪:
Aug 9 06:26:13 10.175.60.14 myPrefix: [error] [TP-Processor114] [my.class.Name] message : exception
at fatherOfException
at fatherof_fatherOfException
at fatherof_fatherof_fatherOfException
...
我的转换模式是
log4j.appender.syslog.layout.ConversionPattern=myPrefix: [%p] [%t] [%c] [%x] - %m%n
那么,是不是可以前缀每一行 with myPrefix,as:
Aug 9 06:26:13 10.175.60.14 myPrefix: [error] [TP-Processor114] [my.class.Name] message : exception
myPrefix at fatherOfException
myPrefix at fatherof_fatherOfException
myPrefix at fatherof_fatherof_fatherOfException
...
当我grep我myPrefix上的日志,我没有看到堆栈跟踪。我们有许多不同的前缀(每个模块一个)
在此先感谢。
感谢您的提示,但这不是我要找的。第一,它会做几个日志而不是一个。第二,我正在研究一个非常大的项目,我无法想象通过其他方式更改每个logger.log。最后,您的解决方案不会在前面加上“at”行前缀。我正在寻找一个log4j配置解决方案。 – 2010-08-11 14:34:13
好吧,对不起。我对log4j不太熟悉,但是当我对它做了一个快速的Google时,我发现这是http://logging.apache.org/log4j/1.2/manual。HTML,你可能已经看到它,但如果你向下滚动到配置大约一半,可能会有所帮助。对不起,我忍不住了。 – Mike 2010-08-11 15:01:17