0

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

Tobia
  • 9,165
  • 28
  • 114
  • 219

1 Answers1

0

Make sure that compile target in ANT (if you use ANT) has the debug attribute set to off as shown below.

<target name="test-compile" depends="compile,test-init">
        <javac destdir="${test.classes.dir}" debug="off" includeantruntime="true" srcdir="${test.dir}">
            <classpath refid="test.compile.classpath">
            </classpath>
        </javac>
    </target>

Also I would check the logging pattern maybe that prints the stack trance. So the stack trace gets printed at the line above the if condition which is:

log.error(e1);
Khush
  • 853
  • 2
  • 8
  • 21