In this section we will discuss what to log and the various levels at which we can generate log statements.
Even though I have mentioned that we should generate log statements when control enters and exits a method, this is a rather controversial point. Especially generating log statements on exiting; because a method could have multiple exit routes. What do you think? I would say, if in doubt - do NOT generate logs when exiting a method. Logs that show control has entered a method do have value in my personal opinion, however you can leave those out as well if you do not see much value in them.
Let me first draw your attention to the output from last page.
0 [main] DEBUG LoggerTest - Entering main
453 [main] DEBUG LoggerTest - Exiting main
What is DEBUG? As I have explained, we should log several events from our program as it executes. But all events are not equally important. Hence, Log4J supports six levels for logging, where each level is appropriate for a certain type of log statement. The levels are (starting from the most severe) FATAL, ERROR, WARN, INFO, DEBUG, and TRACE. Log4J also allows us to dynamically (through a configuration file) filter logs below a certain level. This way we can generate logs only for events that have a priority of WARN or higher and turn on the lower levels when there is a problem, due to which we want to see all the generated log statements.
This tutorial on JBoss does a very good job of explaining logging conventions in JBoss. I have excerpted the part that explains different logging levels below.
Discuss this post in the learning forum.
- Buy programming books from our Amazon.com powered storefront.
- Earn as you browse. Sign up for Algoco.
Note: This text was originally posted on my earlier blog at http://www.adaptivelearningonline.net