【问题标题】:What is the difference between e.printStackTrace(System.out) and e.printStackTrace()?e.printStackTrace(System.out) 和 e.printStackTrace() 有什么区别?
【发布时间】:2020-09-19 13:28:03
【问题描述】:

2 个问题:

  1. e.printStackTrace(System.out) 和 e.printStackTrace() 有什么区别?
  2. 如果我想打印堆栈,使用 logger.error("", e) 将 e.printStackTrace(System.out) 和 e.printStackTrace() 替换为 log4j 是否安全(从生产的角度来看)在我的日志文件中跟踪?

【问题讨论】:

  • Throwable.printStackTrace() 打印到System.err
  • Throwable.printStackTrace(System.out) 是做什么的? @JohannesKuhn
  • 您阅读过 API 文档吗?而是将其打印到提供的非默认输出 System.out

标签: java exception logging log4j


【解决方案1】:
  1. e.printStackTrace() 等同于e.printStackTrace(System.err). So, it prints to standard error. e.printStackTrace(System.out)` 打印到系统输出。

  2. 你不应该在生产代码上使用e.printStackTrace()System.out.print()System.err.print()。您应该始终使用记录器方法,并配置您的记录器。

【讨论】:

    猜你喜欢
    • 2011-08-16
    • 2013-07-24
    • 2013-08-03
    • 2011-10-29
    • 2012-03-22
    • 2015-12-26
    • 1970-01-01
    • 2021-03-01
    • 1970-01-01
    相关资源
    最近更新 更多