情況:系統(tǒng)拋出異常郭怪,日志沒(méi)有打印堆棧信息 錯(cuò)誤日志正常打印
分析:異常信息打印格式?jīng)]有錯(cuò)誤,本地測(cè)試沒(méi)有問(wèn)題,線上其他環(huán)境也沒(méi)有類似的情況帘营。 可能是jvm禁掉了某些
東西,導(dǎo)致了異常信息沒(méi)有打印出來(lái)
資料:https://stackoverflow.com/questions/2295015/log4j-not-printing-the-stacktrace-for-exceptions
https://www.oracle.com/technetwork/java/javase/relnotes-139183.html
虛擬機(jī)部分
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.
譯文:服務(wù)器VM中的編譯器現(xiàn)在為所有“冷”內(nèi)置異常提供正確的堆椫鸸回溯芬迄。出于性能目的,當(dāng)拋出這樣的異常幾次時(shí)昂秃,可以重新編譯該方法禀梳。重新編譯之后,編譯器可以使用不提供堆棧跟蹤的預(yù)分配異常來(lái)選擇更快的策略肠骆。要完全禁用預(yù)分配的異常算途,請(qǐng)使用以下新標(biāo)志: -XX:-OmitStackTraceInFastThrow。
結(jié)論:虛擬機(jī)打印堆棧超過(guò)一定次數(shù)以后蚀腿,會(huì)關(guān)閉掉異常堆棧的打印嘴瓤,通過(guò)-XX:-OmitStackTraceInFastThrow
參數(shù)可禁用 掉該優(yōu)化