Log4j truncates the stack

I am having trouble printing stacktrace in a 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 register an exception like this in my UserGuard.java class:

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

This leads to my application.log:

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

No stack trace. This is really annoying. Thanks!

I tried with the same pom.xml and the same log4j.properties on another machine and it works fine. Should I think that the problem is in my version of Java?

+6
source share
2 answers

The stack trace is likely to be truncated due to optimization in Hotspot. Optimization only builds an identical stacktrace a limited number of times, and then future instances of the exception from the same place do not build it.

You can turn off this optimization using the -XX:-OmitStackTraceInFastThrow or go back to earlier logs to find the first instance of this exception (it is logged once and then optimized later).

See this related fooobar.com/questions/18262 / ... and this and this blog post here .

+6
source

Source: https://habr.com/ru/post/904597/


All Articles