之前一直用e.getMessage()来获取错误信息
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class ClassForTest {
Logger logger = LoggerFactory.getLogger(this.getClass());
@RequestMapping("/xl/test")
public String main111() {
Integer z = null;
try {
z.intValue();
} catch (Exception e) {
logger.error("e.getMessage() = "+e.getMessage());
// logger.error("报错。。", e);
}
return "aaaa";
}
}
输出的日志信息只有一个 null ,其余什么都没有了,非常不利于查找错误的原因
logger.error(“自定义错误信息描述”,e)可打印详细的日志信息,包括具体是哪一行代码报的错都会明确的显示出来
package com.omomcam.controller.xl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class ClassForTest {
Logger logger = LoggerFactory.getLogger(this.getClass());
@RequestMapping("/xl/test")
public String main111() {
Integer z = null;
try {
z.intValue();
} catch (Exception e) {
// logger.error("e.getMessage() = "+e.getMessage());
logger.error("报错。。", e);
}
return "aaaa";
}
}