log4j not printing the stacktrace for exceptions

后端 未结 8 1708
清酒与你
清酒与你 2020-12-04 13:54

I am using log4j with tomcat. When I log exceptions in my JSPs, servlets:

private Logger _log = Logger.getLogger(this.getClass());
...
try{...} catch (Except         


        
8条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-04 14:41

    Actually, it's probably due to a hotspot optimization: after a certain number of the same exception being thrown it stops printing out trace. This can be turned off with a VM arg, see:

    From http://www.oracle.com/technetwork/java/javase/relnotes-139183.html :

    The compiler in the server VM now provides correct stack backtraces for all "cold" built-in exceptions. For performance purposes, when such an exception is thrown a few times, the method may be recompiled. After recompilation, the compiler may choose a faster tactic using preallocated exceptions that do not provide a stack trace. To disable completely the use of preallocated exceptions, use this new flag: -XX:-OmitStackTraceInFastThrow.

    More here:

    http://jawspeak.com/2010/05/26/hotspot-caused-exceptions-to-lose-their-stack-traces-in-production-and-the-fix/

提交回复
热议问题