我有这个处理程序:
public class JsonHandlerExceptionResolver implements HandlerExceptionResolver {
private static Logger log = Logger.getLogger(JsonHandlerExceptionResolver.class);
@Override
@ResponseBody
public ModelAndView resolveException(HttpServletRequest req, HttpServletResponse response, Object obj, Exception e) {
Output out=new Output(false);
out.setException(e.getClass().getName());
out.setError(e.getLocalizedMessage());
response.setContentType("application/json");
log.error(e.getMessage());
if(log.isDebugEnabled()) e.printStackTrace();
try{
response.getWriter().println(new Gson().toJson(new Output(e.getMessage(),e.getClass().getSimpleName())));
response.getWriter().flush();
response.getWriter().close();
}catch (Exception e1) {
log.error(e1);
if(log.isDebugEnabled()) e1.printStackTrace();
}
return null;
}
}
如果未启用日志调试级别,我不想将堆栈跟踪打印到 jvm sterr,但是我因此在此处理程序之后输出堆栈跟踪...你能告诉我为什么吗?
调试我看到 log.isDebugEnabled() 在我的测试中是正确的错误