Skip to content

Loging Levels

October 19, 2014

Most logging frameworks (Logback, Log4J, JDK Logging) have them; but are we using them correctly? When is it a WARN instead of an ERROR; should DEBUG be used or TRACE and what about INFO?

Not logging at the right level could render what potentially might be useful logs into swaths of pointless bytes accumulating diskspace for no reason. The result is no-one bothers to look at the logs cause “they’re a pile of sh*t“.

SO here I’ve outlined some rules of thumb that I use for my projects when logging:

ERROR: The system is in real distress and an urgent fix WILL be required IMMEDIATELY. Customers are probably being affected. The “2:00 AM rule” applies here; if you’re on call, do you want to be woken up  if this condition happens? If yes, then definitely log me as “ERROR“.

WARN: An unexpected technical or business event happened. Somme customers might be affected slightly but the applications major functionalities are still operational. No immediate intervention is required. Should the person on call be woken up? If “no” then it’s a “WARN“; but support personnel will want to review this issue ASAP to understand what’s the impact. Basically any issue that needs to be tracked and acted upon but may not require immediate intervention.

INFO: Things of high volume such as system event life-cycles (start-up, shutdown) go here. “Session” life-cycle (login, logout, etc.). Boundary events should be considered as well (e.g. API calls, database calls). And typical business exceptions that is NOT an error can go here (e.g. login failed due to bad credentials). Is this a normal event/transition that could occur? If “yes” then log as INFO.

DEBUG: Any message that is helpful in tracking the flow through the system and isolating issues, especially during the development and QA phases. Is this information interesting for programmers? If “yes” then log it as DEBUG.

TRACE: Not often used but extremely useful for detailed logs. Typically not enabled during normal development but nevertheless necessary in case the system needs to be forensically analysed. Examples include dumping a full object hierarchy, logging every state during loop iterations etc. Need to analyse in detail the flow of a program; if the “yes” then use TRACE.

Hope this has helped you; any suggestions/improvements welcomed as ever 🙂


From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: