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

后端 未结 6 1225
感情败类
感情败类 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 19:10

    If you are using a Java version previous to 8, you can try this:

                LOGGER.error("Error al recuperar proveedores de la base de datos: " + 
                e + Arrays.asList(e.getStackTrace()).stream().map(new Function(){
                        @Override
                        public Object apply(Object t) {
                            return t.toString();
                        }
                    }).collect(Collectors.joining("\n")));
    

提交回复
热议问题