Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What information to include at each log level? [duplicate]

Tags:

java

logging

Possible Duplicates:
Where/what level should logging code go?
Debug Levels

Is there a convention, a standard, or a widely used guide which will help with logging in Java? Specifically, what to include at each level (verbose, debug, ... etc.) rather than the actual mechanism of logging.

There are many guides out there of what to include at each log level, but none of them are specific; they're all vague, and this makes it hard to "follow orders".

Any tips would be appreciated.

like image 954
Gallal Avatar asked Feb 02 '11 11:02

Gallal


1 Answers

It's subject to personal interpretation, but mine is (in order from finest to coursest):

  • Trace - The finest logging level. Can be used to log very specific information that is only relevant in a true debugging scenario, e.g., log every database access or every HTTP call etc.
  • Debug - Information to primary help you to debug your program. E.g., log every time a batching routine empties its batch or a new file is created on disk etc.
  • Info - General application flow, such as "Starting app", "connecting to db", "registering ...". In short, information which should help any observer understand what the application is doing in general.
  • Warn - Warns of errors that can be recovered. Such as failing to parse a date or using an unsafe routine. Note though that we should still try to obey the fail fast principle and not hide e.g., configuration errors using warning message, even though we a default value might be provided by the application.
  • Error - Denotes an often unrecoverable error. Such as failing to open a database connection.
  • Fatal/Critical Used to log an error the application cannot recover from, which might lead to an immediate program termination.

In the end it's up to you to define what suits you best. Personally, I run most production system with logging level of Info, where I'm mostly interested in following the applications main logic, and of course catch all warnings/errors.

Except for code cluttering, there is no such thing as too much logging. All logging which helps you reproduce or understand problems better are good logging. On a performance note, most logging systems (e.g., log4j) allows configuring which level to actually append to the physical log which is a great thing.

like image 74
Johan Sjöberg Avatar answered Oct 09 '22 09:10

Johan Sjöberg