Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Usage of log4J levels

Tags:

log4j

What is the best practice in using log4j levels while coding. I mean when do we use INFO logging, when do we use DEBUG logging / ERROR logging etc.

like image 834
Eager Learner Avatar asked Dec 30 '09 04:12

Eager Learner


People also ask

What is the purpose of logging levels?

A logging level is a way of classifying the entries in your log file in terms of urgency. Classifying helps filter your log files during search and helps control the amount of information in your logs. Sometimes, categorizing may require you to balance storage use.

For what purpose log4j is used?

Log4j is a logging framework written in Java that provides an easy way for logging in Selenium. In a nutshell, the framework gives out information about everything that goes on during the software execution. Log4j also provides insight into anything that may have gone wrong during software execution or automation.

What is the default logging level in log4j?

Note that by default Log4j assigns the root logger to Level. ERROR.


2 Answers

In general, I follow these guidelines:

  • DEBUG : low level stuff. cache hit, cache miss, opening db connection
  • INFO : events that have business meaning - creating customer, charging cc...
  • WARN : could be a problem but doesn't stop your app. email address not found / invalid
  • ERROR : unexpected problem. couldn't open db connection. etc...
like image 131
Mike Valenty Avatar answered Oct 01 '22 08:10

Mike Valenty


My baseline is always that INFO level is equivalent to System.out, and ERROR is equivalent to System.err.

DEBUG - Here you put all your tracing information, and specifically information that you don't want to see when your "comfort level" is system.out.

INFO - use this one for general messages, progress messages, for application related messages, but not for tracing.

WARN - provide alerts that something is wrong, perhaps unexpected, or that a workaround is used, but the application can still continue (socket timeout/retries, invalid user input, etc.).

ERROR - alerts about problems that prevent your app from continuing normally, e.g. database is down, missing bootstrap configuration.

A common mistake when writing libraries is to use ERROR level to indicate problems with the calling application (the code that uses the library) instead of indicating real errors within the library itself. See for example this hibernate bug -> http://opensource.atlassian.com/projects/hibernate/browse/HHH-3731

This is really annoying because messages from ERROR level are really difficult to suppress, so use them only to indicate problems with your own code.

All - I don't really use this one, it is practically the same as DEBUG or TRACE.

like image 42
Yoni Avatar answered Oct 01 '22 10:10

Yoni