log4j not printing the stacktrace for exceptions

后端 未结 8 1691
清酒与你
清酒与你 2020-12-04 13:54

I am using log4j with tomcat. When I log exceptions in my JSPs, servlets:

private Logger _log = Logger.getLogger(this.getClass());
...
try{...} catch (Except         


        
8条回答
  •  温柔的废话
    2020-12-04 14:37

    You can add these lines of code in your catch block.

    catch (SQLException e) {
                CharArrayWriter cw = new CharArrayWriter();
                PrintWriter w = new PrintWriter(cw);
                e.printStackTrace(w);
                w.close();
                String trace = cw.toString();
    
        log.error("This is complete stacktrace", trace);
    }
    

提交回复
热议问题