简体   繁体   English

log4j截断堆栈跟踪

[英]log4j truncates stacktrace

I'm having a problem printing the stacktrace to my log file. 我在将堆栈跟踪打印到我的日志文件时遇到问题。 Log4j.properties: Log4j.properties:

log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=/var/log/app/application.log
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %c{1} [%p] %m%n

log4j.rootLogger=warn, file
log4j.logger.com.app=info, file
log4j.additivity.com.app=false

when I log an exception like this in my class UserGuard.java: 当我在我的类UserGuard.java中记录这样的异常时:

} catch (Exception e) {
    log.error("Uncaught error", e);
    response.setEntity(new StringRepresentation(" "));
    response.setStatus(Status.SERVER_ERROR_INTERNAL);
}

This results in my application.log : 这导致我的application.log:

2011-12-28 07:30:03 UserGuard [ERROR] Uncaught error
java.lang.NullPointerException

No stack trace shown. 没有显示堆栈跟踪。 This is really annoying. 这真的很烦人。 Thanks! 谢谢!

Tried with same pom.xml and same log4j.properties on another machine and works ok. 在另一台机器上尝试使用相同的pom.xml和相同的log4j.properties并且正常工作。 Should I think that the problem is my java version? 我应该认为问题是我的java版本吗?

Your stack traces are most likely getting truncated due to an optimization in Hotspot. 由于Hotspot中的优化,您的堆栈跟踪很可能会被截断。 The optimization only builds the identical stacktrace a limited number of times, and then future instances of the exception from the same exact place don't build it. 优化仅构建相同的堆栈跟踪有限次数,然后来自同一确切位置的异常的未来实例不会构建它。

You can either turn off this optimization using the -XX:-OmitStackTraceInFastThrow flag, or go back to earlier logs to find the first instance of this exception occuring (it's logged once, then optimized away later). 您可以使用-XX:-OmitStackTraceInFastThrow标志关闭此优化,或者返回到早期日志以查找此异常发生的第一个实例(它已记录一次,然后稍后进行优化)。

See this related StackOverflow question , and this one , and this blog post over here . 请参阅此相关的StackOverflow问题 ,以及 文章和此博客文章

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM