log4j does not print the exception stack

  • 2021-01-19 22:15:42
  • OfStack

This article focuses on log4j which does not print the exception stack as follows.

Recently, we found a phenomenon in the error log of the system online:

log4j is used in the code to print the system runtime exception stack information, in the error log can not see the stack information, only exception information. This is a shock to programmers, no stack information to look up bug.

[

[01-15 11:29:26] [ERROR] [org.apache.thrift.server.AbstractNonblockingServer$FrameBuffer:524] Unexpected throwable while invoking!

]

This was later found to be an optimization of jdk. JVM is optimized for performance. If an exception is thrown frequently, it is recompiled and the exception stack is not printed.

If you don't want to look up the previous log to see the stack every time, you can simply add -XX:-OmitStackTraceInFastThrow to the boot parameter to disable the optimization and force the exception stack to be printed. This may cause the log file to be too large, but the log file on the production line will be compressed until today, so it doesn't feel like a problem.

[

[01-15 16:40:09] [ERROR] [org.apache.thrift.server.AbstractNonblockingServer$FrameBuffer:524] Unexpected throwable while invoking!
java.lang.NullPointerException
at com.iqiyi.ttbrain.recommend.selector.services.FilterService.filter2(FilterService.java:42)
at com.iqiyi.ttbrain.recommend.thrift.IFilterService$Processor$filter2.getResult(IFilterService.java:181)
at com.iqiyi.ttbrain.recommend.thrift.IFilterService$Processor$filter2.getResult(IFilterService.java:166)
at org.apache.thrift.ProcessFunction.process(ProcessFunction.java:39)
at org.apache.thrift.TBaseProcessor.process(TBaseProcessor.java:39)
at org.apache.thrift.server.AbstractNonblockingServer$FrameBuffer.invoke(AbstractNonblockingServer.java:518)
at org.apache.thrift.server.Invocation.run(Invocation.java:18)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)

]

conclusion

The above is this article about log4j does not print the exception stack of all content, I hope to help you. Interested friends can continue to refer to the site of other related topics, if there are shortcomings, welcome to leave a message to point out. Thank you for your support!


Related articles: