The difference between logger.info and logger.debug

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

When will logger.debug be printed?

+64
java logging log4j
Feb 26 2018-10-28
source share
7 answers

This will depend on the logging configuration. The default value will depend on the structure used. The idea is that later, changing the configuration setting from INFO to DEBUG, you will see a ton of more (or less, if vice versa) lines printed without recompiling the entire application.

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

+23
Feb 26 2018-10-26T00-02-26
source share

I suggest you take a look at an article entitled β€œA Brief Introduction to log4j” . It provides a brief explanation of journal levels and demonstrates how they can be used in practice. The basic idea of ​​log levels is that you want to customize how detailed the logs are, depending on the situation. For example, if you are trying to fix a problem, you need the logs to be very detailed. In production, you can only see warnings and errors.

The log level for each component of your system is usually controlled by a parameter in the configuration file, so it is easy to change. Your code will contain various logging statements at different levels. When responding to an Exception you can raise Logger.error . If you want to print the value of a variable at any given point, you can call Logger.debug . This combination of custom logging level and logging in your program allows you to fully control how your application will record its activities.

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

 DEBUG < INFO < WARN < ERROR < FATAL 

Here is a brief example from this article that demonstrates how journal 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"); 
+112
Feb 26 '10 at
source share

Just a clarification on the set of all possible levels, which are:

 ALL < TRACE < DEBUG < INFO < WARN < ERROR < FATAL < OFF 
+9
Dec 05 '14 at 15:21
source share

This mainly depends on how your registrars are configured. Typically, you will have debug output written out during development, but disabled during production β€” or you may have selected debug categories when debugging a specific area.

The point at which there are different priorities is to allow you to increase or decrease the level of detail on a particular component reasonably enough, and you only need to change the logging configuration (not the code) to see the difference.

+7
Feb 26 2018-10-26T00-02-26
source share

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

This is only a certain level by default. You can define your levels if you want. The purpose of these levels is to enable / disable one or more of them without making any changes to your code.

When will logger.debug be printed

If you have enabled debugging or some higher level in your configuration.

0
Feb 26 2018-10-28
source share

It depends on what level you selected in the log4j configuration file.

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

If your level is "information" (default), logger.debug(...) will not be printed to the console. However, if your level is "debugged", it will.

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

 ALL < TRACE < DEBUG < INFO < WARN < ERROR < FATAL < OFF 
0
Nov 15 '17 at 13:06 on
source share

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

Each level corresponds / corresponds to the type of user:

  • debugging: developer - manual debugging
  • trace: automated logging and step tracer - to support level 3
  • information: technician / support level 1/2
  • warning: technician / user error: automatic notification / support level 1
  • critical / fatal: depends on your setup - local IT
0
Jul 14 '19 at 11:44
source share



All Articles