gpt4 book ai didi

java - logger.info 和 logger.debug 之间的区别

转载 作者:IT老高 更新时间:2023-10-28 13:51:34 27 4
gpt4 key购买 nike

logger.debuglogger.info 有什么区别?

logger.debug什么时候打印?

最佳答案

我建议你看看这篇名为 "Short Introduction to log4j" 的文章。 .它包含对日志级别的简短说明,并演示了如何在实践中使用它们。日志级别的基本思想是您希望能够根据情况配置日志包含多少详细信息。例如,如果您尝试解决问题,您会希望日志非常详细。在生产环境中,您可能只想看到警告和错误。

系统每个组件的日志级别通常通过配置文件中的参数控制,因此很容易更改。您的代码将包含具有不同级别的各种日志记录语句。响应 Exception 时,您可能会调用 Logger.error。如果您想在任何给定点打印变量的值,您可以调用 Logger.debug。程序中可配置的日志记录级别和日志记录语句的组合允许您完全控制应用程序将如何记录其 Activity 。

至少在 log4j 的情况下,日志级别的顺序是:

DEBUG < INFO < WARN < ERROR < FATAL

这是该文章中的一个简短示例,演示了日志级别的工作原理。

   // get a logger instance named "com.foo"
Logger logger = Logger.getLogger("com.foo");

// Now set its level. Normally you do not need to set the
// level of a logger programmatically. This is usually done
// in configuration files.
logger.setLevel(Level.INFO);

Logger barlogger = Logger.getLogger("com.foo.Bar");

// This request is enabled, because WARN >= INFO.
logger.warn("Low fuel level.");

// This request is disabled, because DEBUG < INFO.
logger.debug("Starting search for nearest gas station.");

// The logger instance barlogger, named "com.foo.Bar",
// will inherit its level from the logger named
// "com.foo" Thus, the following request is enabled
// because INFO >= INFO.
barlogger.info("Located nearest gas station.");

// This request is disabled, because DEBUG < INFO.
barlogger.debug("Exiting gas station search");

关于java - logger.info 和 logger.debug 之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2342280/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com