如何将日志的错误信息打印出来

2025-10-17 15:01:09

1、这里的话我直接给大家代码吧!StringWriter sw = null;        PrintWriter pw = null;        try {            sw = new StringWriter();            pw =  new PrintWriter(sw);           

如何将日志的错误信息打印出来

2、 //将出错的栈信息输出到printWriter中            e.printStackTrace(pw);            pw.flush();            sw.flush();        } finally {           

如何将日志的错误信息打印出来

3、 if (sw != null) {                try {                    sw.close();                } catch (IOException e1) {                    e1.printStackTrace();                }            }            if (pw != null) {                pw.close();            }        }     log.err(sw.toString());

如何将日志的错误信息打印出来

4、log.debug("Request TTL set to: {} ({})", new Date(ttl), ttl); // Request TTL set to: Wed Apr 28 20:14:12 CEST 2010 (1272478452437) 。

如何将日志的错误信息打印出来

5、final String duration = DurationFormatUtils.formatDurationWords(durationMillis, true, true); log.info("Importing took: {}ms ({})", durationMillis, duration); //Importing took: 123456789ms (1 day 10 hours 17 minutes 36 seconds)

如何将日志的错误信息打印出来

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢