【问题标题】:Include logs of external library using printStackTrace使用 printStackTrace 包含外部库的日志
【发布时间】:2020-07-28 05:15:00
【问题描述】:

有一个外部库在 catch 块中使用 e.printStackTrace();

Web 应用程序本身使用 slf4j 和 logback 将日志写入文件(滚动文件追加器)。

有没有办法将这些堆栈跟踪也包含到基于文件的日志中(最好先不修改库)?

【问题讨论】:

    标签: java logback slf4j stderr


    【解决方案1】:

    您可以替换 System.err 流。然后,这将重定向错误流上的任何输出。请注意,outerr 都有。

    Can we replace "out" in System.out.println()? 说:

    System.setErr(PrintStream)

    通过替换 err 流,您可以捕获并重定向 e.printStackTrace,因为它会打印到 System.err

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多