How to send a stacktrace to log4j?

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

    In Log4j 2, you can use Logger.catching() to log a stacktrace from an exception that was caught.

        try {
            String msg = messages[messages.length];
            logger.error("An exception should have been thrown");
        } catch (Exception ex) {
            logger.catching(ex);
        }
    

提交回复
热议问题