How to send a stacktrace to log4j?

后端 未结 11 974
失恋的感觉
失恋的感觉 2020-11-29 19:29

Say you catch an exception and get the following on the standard output (like, say, the console) if you do a e.printStackTrace() :

java.io.FileNotFo         


        
11条回答
  •  情歌与酒
    2020-11-29 20:02

    Just because it happened to me and can be useful. If you do this

    try {
       ...
    } catch (Exception e) {
        log.error( "failed! {}", e );
    }
    

    you will get the header of the exception and not the whole stacktrace. Because the logger will think that you are passing a String. Do it without {} as skaffman said

提交回复
热议问题