【问题标题】:How to log messages with level ERROR如何记录级别为 ERROR 的消息
【发布时间】:2014-02-28 09:03:56
【问题描述】:
catch (Exception e) {
            e.printStackTrace();
            System.out.println("Exception in go method: " + e);
            logger.log(Level.SEVERE, e.toString());
        }

1) 像我上面所做的那样,如何记录 Level 为 ERROR 而不是 SEVERE 的消息。

2) 在记录上述消息时,我们应该调用 e.toString() 还是 e.getMessage() ?哪个更实用?

【问题讨论】:

    标签: java exception logging exception-handling error-handling


    【解决方案1】:

    1) 看起来您正在使用 java.util.logging。 JUL 中没有 Level.ERROR。严重的是正确的对应物。 2) 更好的选择是 logger.log(Level.SEVERE, "Exception in go method", e)。这可能会记录完整的调用堆栈。

    最后...看看 slf4j 的日志记录

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-24
      • 2019-06-06
      • 2016-06-30
      • 2019-05-07
      • 2020-04-16
      • 2016-02-20
      相关资源
      最近更新 更多