Logging

Created at 2017-11-01 Updated at 2024-11-07 - 2 min. read Category experience / work Tag log / logging / best-practice

Logging is a fine art. It takes experience to know what to log and what not.

I’ve found that the best way of learning the art of logging is by experiencing the pain of attempting to diagnose issues with bad logging.

Some of things I learned while going through the code were:

Log with proper message

Always keep in mind while logging that what the log message says to the person who is reading it. For example while logging the error while signup should be logged like
console.log("signup error : ", signuperr);
rather than
console.log(signuperr);
As in the above example it is hard to know as what and where was the error.

A common mistake is to not think about what information is required when logging, however you should also think carefully about when a message will be logged - if a message is logged frequently under normal operation then at best it’s usefulness is questionable and at worst that log message can be misleading.

Log only when there is problem

Please don’t confuse logging with error handling. Error handling is done in a fully controlled flow. What need to be logged is what goes out of the flow. Sometimes there is more extra information offered in logs than what is needed.
So my suggestion is to log only when actually you need and proble arises.

Site by Ashutosh Kumar Singh using Hexo & Random

Traveller - Developer - Foodie - Biker - Cyclist - Rider - Technocrat