logger.debug
和logger.info
有什么区别?
什么时候打印logger.debug
?
发布于 2010-02-26 22:38:11
这将取决于日志记录配置。默认值将取决于所使用的框架。这个想法是,稍后通过将配置设置从INFO更改为DEBUG,您将看到更多(或者更少,反之亦然)的行打印,而无需重新编译整个应用程序。
如果你想使用哪一个,那么归根结底就是你想在哪个级别上看到什么。有关Log4J中的其他级别,请查看API、http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/Level.html
发布于 2010-02-26 22:41:03
我建议你看看这篇名为"Short Introduction to log4j"的文章。它包含对日志级别的简短解释,并演示了如何在实践中使用它们。日志级别的基本思想是,您希望能够根据情况配置日志包含的详细信息。例如,如果您正在尝试对问题进行故障排除,您可能希望日志非常详细。在生产环境中,您可能只希望看到警告和错误。
系统中每个组件的日志级别通常通过配置文件中的参数进行控制,因此很容易更改。您的代码将包含不同级别的各种日志记录语句。在响应Exception
时,您可以调用Logger.error
。如果想要在任何给定点打印变量的值,可以调用Logger.debug
。程序中的可配置日志记录级别和日志记录语句的这种组合允许您完全控制应用程序将如何记录其活动。
至少对于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");
发布于 2014-12-05 23:21:13
只是对所有可能级别的集合进行澄清,即:
ALL < TRACE < DEBUG < INFO < WARN < ERROR < FATAL < OFF
https://stackoverflow.com/questions/2342280
复制相似问题