How do you write a full stack trace to the log?

后端 未结 6 1398
感情败类
感情败类 2021-02-18 18:07

I was catching an exception and trying to write the stack trace to the logs like this:

log.warn(e.getMessage());

But all it said was

         


        
6条回答
  •  一个人的身影
    2021-02-18 18:44

    Using log4j this is done with:

    logger.error("An error occurred", exception);
    

    The first argument is a message to be displayed, the second is the exception (throwable) whose stacktrace is logged.

    Another option is commons-logging, where it's the same:

    log.error("Message", exception);
    

    With java.util.logging this can be done via:

    logger.log(Level.SEVERE, "Message", exception);
    

提交回复
热议问题