Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between logger.info and logger.debug

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

When will logger.debug be printed?

like image 655
Senthilnathan Avatar asked Feb 26 '10 14:02

Senthilnathan


People also ask

What is the difference between logger INFO and logger debug?

INFO is used to log the information your program is working as expected. DEBUG is used to find the reason in case your program is not working as expected or an exception has occurred. it's in the interest of the developer.

What does debug logging mean?

Debug logging is a troubleshooting process that gathers a large amount of information and system logs to help find problems. We recommend only enabling this for a short time, as the log files can become very large on the end device.

Which is higher INFO or debug?

DEBUG is lower level than Info.

Does log level INFO show debug?

A log level used for events considered to be useful during software debugging when more granular information is needed. A log level describing events showing step by step execution of your code that can be ignored during the standard operation, but may be useful during extended debugging sessions.


1 Answers

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.

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.

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

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"); 
like image 164
William Brendel Avatar answered Sep 29 '22 23:09

William Brendel