How to send a stacktrace to log4j?

后端 未结 11 971
失恋的感觉
失恋的感觉 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:20

    You pass the exception directly to the logger, e.g.

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

    It's up to log4j to render the stack trace.

提交回复
热议问题