Tips for Proper Application Logging
- Use the appropriate tools for logging. SLF4J is the best logging API available, mostly because of a great pattern support.
- SLF4J provides logging levels for you.
- ERROR – something terribly wrong had happened, that must be investigated immediately. No system can tolerate items logged on this level. Example: NPE, database unavailable, mission critical use case cannot be continued
- WARN – the process might be continued, but take extra caution. Actually I always wanted to have two levels here: one for obvious problems where work-around exists (for example: “Current data unavailable, using cached values”) and second (name it: ATTENTION) for potential problems and suggestions.
- DEBUG – Developers tool to keep the track of the flow of operation in the application.
- Exactly specify the log message so that it reflect what the method does.
i.e. - Use logger.debug("") to show the flow of the operations (name of method and what it does) after logical operations in a method with an appropriate message. This helps to easily figure out where the application is stuck.
0 Comments