Application logging good practice

Mainly used logging levels are INFO, DEBUG and ERROR.

INFO: Info level enabled by default on the all the environment.But what should be there in info level. Info log should teach us application's request path at any point of time when we look at log. It means method should have entry and exit info excluding getter, setters and tiny methods which has no value. Every if-else condition should have info log but exclude where ever no much value. For Instance, some conditions and methods we know that always entry and exit.

DEBUG: Debug level is enabled mostly below production environment or whenever debugging is required. Debug log statements go along with info log statement but where ever there are more info to logging. For instance, all method parameters on method entry and method state or return value on method exit. if condition value logging before entry into any if-else conditions. But all limited to where ever make no sense.

ERROR: Error level is enabled by default all the environment. Error logging statement would always come where ever exception is being caught. But it should have always printStackTrace apart from any application level custom message. Just only message on error statement would make hard to troubleshoot.  

To view or add a comment, sign in

More articles by Sudhagar Nagarajan

Explore content categories