GAE how to see production exceptions?

2019-05-20 08:12发布

I'm getting an error on the production env but not on the local one. Is there a way to see the exception that is probably being thrown from production? In tomcat - the user will be able the see the exception as the servlet returns its output

1条回答
萌系小妹纸
2楼-- · 2019-05-20 08:44

You (the administrator) can see the exception (including full stack trace) in the log viewer on the admin console.

If you want to display the exception stacktrace to your users, you can install a Servlet filter that catches everything and prints the stacktrace to the response stream (you should then log it as SEVERE also, in order to still have it show up in the log).

Something like this:

public class ExceptionLogger implements Filter {

    @Override
    public void init(FilterConfig config) throws ServletException {
    }

    @Override
    public void destroy() {
    }

    @Override
    public void doFilter(ServletRequest arg0, ServletResponse arg1,
        FilterChain arg2) throws IOException, ServletException {

        try{
           arg2.doFilter(arg0, arg1);
        } catch (Exception e) {
           Logger.getLogger("ExceptionLogger").log(Level.SEVERE,
              "request failed with an exception", e);
           e.printStacktrace(arg1.getWriter());
        }
    }
}

And you can set it to filter all pages in web.xml with a url-pattern of "*".

PS: There is no Tomcat, GAE/J is running Jetty.

查看更多
登录 后发表回答