简体   繁体   English

如何记录错误级别为ERROR的消息

[英]How to log messages with level ERROR

catch (Exception e) {
            e.printStackTrace();
            System.out.println("Exception in go method: " + e);
            logger.log(Level.SEVERE, e.toString());
        }

1) How is it possible to log messages with Level being ERROR instead of SEVERE as I do above. 1)如何记录级别为ERROR而不是上面的SEVERE消息。

2) when logging message like the one above, should we call e.toString() or e.getMessage() ? 2)在记录上述消息时,应调用e.toString()还是e.getMessage() which is more practical? 哪个更实用?

1) It looks like you are using java.util.logging. 1)看起来您正在使用java.util.logging。 There is no Level.ERROR in JUL. JUL中没有Level.ERROR。 Severe is the right counterpart. 严格是正确的选择。 2) Better alternative is logger.log(Level.SEVERE, "Exception in go method", e). 2)更好的替代方法是logger.log(Level.SEVERE,“ go方法中的异常”,e)。 This probably will log the full call stack. 这可能会记录完整的调用堆栈。

And finally... look at slf4j for logging 最后...查看slf4j进行日志记录

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM