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

后端 未结 6 1243
感情败类
感情败类 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:58

    You can use

    logger.log(Level.WARN, "logged exception", ex);
    

    or

    logger.warn("logged exception", ex);
    

    Resources :

    • How to print the stack trace of an exception using Log4J (or Commons Logging)
    • logging.apache.org - Category

提交回复
热议问题