Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does log4j disable stack trace after (lots of) repetition of the same exception?

At one of our customer installations we had thousands of occurrences of the same exception. After a lot of well logged stacktraces (9332) the occurrence of the exception is still logged, but without stacktrace. After restarting the java process, the same thing: This time we had 17858 stacktraces and then only the exception occurrence itself.

There is a similar question here, but no answer...

Is it a log4j feature or bug? (I believe in the former, because I really like, what those apache guys do)

Any ideas?

like image 917
Kai Huppmann Avatar asked Jul 17 '09 08:07

Kai Huppmann


2 Answers

Using Java 5 or better?

Then you're seeing:

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

Courtesy of the Java 5 release notes.

like image 101
Robert Munteanu Avatar answered Nov 20 '22 04:11

Robert Munteanu


Sounds like a feature to me, at least if the stack traces really are identical. Why would you want to make your logs bigger (and thus harder to search) without getting any more information? Will check for configurability of this feature...

EDIT: I've had a look through the log4j code and there's no trace of it. This would strongly suggest that Robert's answer is correct. Nice VM feature IMO :)

like image 21
Jon Skeet Avatar answered Nov 20 '22 04:11

Jon Skeet