I'm having a problem printing the stacktrace to my log file. 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:
} catch (Exception e) {
log.error("Uncaught error", e);
response.setEntity(new StringRepresentation(" "));
response.setStatus(Status.SERVER_ERROR_INTERNAL);
}
This results in my 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. Should I think that the problem is my java version?
Your stack traces are most likely getting truncated due to an optimization in 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).
See this related StackOverflow question, and this one, and this blog post over here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With