Java logger.info 和 logger.debug 的区别

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2342280/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 06:22:02  来源:igfitidea点击:

Difference between logger.info and logger.debug

javalogginglog4j

提问by Senthilnathan

What is the difference between logger.debugand logger.info?

logger.debug和 和有logger.info什么区别?

When will logger.debugbe printed?

什么时候logger.debug印刷?

采纳答案by toomasr

This will depend on the logging configuration. The default value will depend on the framework being used. The idea is that later on by changing a configuration setting from INFO to DEBUG you will see a ton of more (or less if the other way around) lines printed without recompiling the whole application.

这将取决于日志记录配置。默认值将取决于所使用的框架。这个想法是,稍后通过将配置设置从 INFO 更改为 DEBUG,您将看到大量(或更少,如果相反)打印的行,而无需重新编译整个应用程序。

If you think which one to use then it boils down to thinking what you want to see on which level. For other levels for example in Log4J look at the API, http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/Level.html

如果您考虑使用哪个,那么归结为您想在哪个级别上看到什么。对于其他级别,例如在 Log4J 中查看 API,http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/Level.html

回答by Jon Skeet

Basically it depends on how your loggers are configured. Typically you'd have debug output written out during development but turned off in production - or possibly have selecteddebug categories writing out while debugging a particular area.

基本上,这取决于您的记录器的配置方式。通常,您会在开发期间写出调试输出,但在生产中关闭 - 或者可能在调试特定区域时选择了写出的调试类别。

The point of having different priorities is to allow you to turn up/down the level of detail on a particular component in a reasonably fine-grained way - and only needing to change the logging configuration (rather than code) to see the difference.

具有不同优先级的要点是允许您以合理的细粒度方式调高/调低特定组件的细节级别 - 并且只需要更改日志配置(而不是代码)即可查看差异。

回答by William Brendel

I suggest you look at the article called "Short Introduction to log4j". It contains a short explanation of log levels and demonstrates how they can be used in practice. The basic idea of log levels is that you want to be able to configure how much detail the logs contain depending on the situation. For example, if you are trying to troubleshoot an issue, you would want the logs to be very verbose. In production, you might only want to see warnings and errors.

我建议你看看名为“Short Introduction to log4j”的文章。它包含对日志级别的简短说明,并演示如何在实践中使用它们。日志级别的基本思想是您希望能够根据情况配置日志包含的详细信息。例如,如果您尝试对问题进行故障排除,您会希望日志非常详细。在生产中,您可能只想查看警告和错误。

The log level for each component of your system is usually controlled through a parameter in a configuration file, so it's easy to change. Your code would contain various logging statements with different levels. When responding to an Exception, you might call Logger.error. If you want to print the value of a variable at any given point, you might call Logger.debug. This combination of a configurable logging level and logging statements within your program allow you full control over how your application will log its activity.

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

In the case of log4j at least, the ordering of log levels is:

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

DEBUG < INFO < WARN < ERROR < FATAL

Here is a short example from that article demonstrating how log levels work.

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

   // 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");

回答by craftsman

What is the difference between logger.debug and logger.info?

logger.debug 和 logger.info 有什么区别?

These are only some default level already defined. You can define your own levels if you like. The purpose of those levels is to enable/disable one or more of them, without making any change in your code.

这些只是一些已经定义的默认级别。如果您愿意,您可以定义自己的级别。这些级别的目的是启用/禁用其中一个或多个,而无需对代码进行任何更改。

When logger.debug will be printed ??

logger.debug 什么时候会被打印出来??

When you have enabled the debug or any higher level in your configuration.

当您在配置中启用调试或任何更高级别时。

回答by user1823890

Just a clarification about the set of all possible levels, that are:

只是对所有可能级别的集合的澄清,即:

ALL < TRACE < DEBUG < INFO < WARN < ERROR < FATAL < OFF

回答by Hyman'

It depends on which level you selected in your log4j configuration file.

这取决于您在 log4j 配置文件中选择的级别。

<Loggers>
        <Root level="info">
        ...

If your level is "info" (by default), logger.debug(...)will not be printed in your console. However, if your level is "debug", it will.

如果您的级别是“信息”(默认情况下),logger.debug(...)则不会在您的控制台中打印。但是,如果您的级别是“调试”,则可以。

Depending on the criticality level of your code, you should use the most accurate level among the following ones :

根据代码的严重程度级别,您应该使用以下级别中最准确的级别:

ALL < TRACE < DEBUG < INFO < WARN < ERROR < FATAL < OFF

回答by Mickey Perlstein

This is a very old question, but i don't see my understanding here so I will add my 2 cents:

这是一个非常古老的问题,但我在这里没有看到我的理解,所以我将添加我的 2 美分:

Every level corresponds/maps to a type of user:

每个级别对应/映射到一种用户:

  • debug : developer - manual debugging
  • trace : automated logging and step tracer - for 3rd level support
  • info : technician / support level 1 /2
  • warn : technician / user error : automated alert / support level 1
  • critical/fatal : depends on your setup - local IT
  • 调试:开发人员 - 手动调试
  • trace :自动日志记录和步骤跟踪器 - 用于第 3 级支持
  • 信息:技术员/支持级别 1 /2
  • 警告:技术人员/用户错误:自动警报/支持级别 1
  • 关键/致命:取决于您的设置 - 本地 IT