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

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

    If you using Java 8 you can do the following:

    LOGGER.error("Caught exception while methodX. Please investigate: " 
        + exception 
        + Arrays.asList(exception.getStackTrace())
        .stream()
        .map(Objects::toString)
        .collect(Collectors.joining("\n"))
    );
    

提交回复
热议问题