I have this handler:
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;
}
}
In case of log Debug-Level not enabled I don't want to print the stacktrace to the jvm sterr, however I so the stack trace outputted just after this handler... can you tell me why?
Debugging i saw that log.isDebugEnabled() is correctly false during my tests