(Tutorial) Java Tutorial - Logging Basics
Tutorial : Java Tutorial - Logging Basics
Logging basics
Logging can be defined as a process of storing information about events that occurred during program execution. There are different options to show/store log messages:
- show on console
- store in a file
- send to a remove monitor
Choosing the right option depends on the requirements and type of application.
Normally every java coder does logging even if he is not uing any logging framework. For instance, System.out.println statement is used to print informative message on the console. These messages can also contain the timestamp and other useful information which will make these messages interesting for the viewer and can help in error tracking and performance monitoring. But if you use a logging framework, then there is a big plus. The logging framework adds contextual information like line number, timestamp etc which prevents the developers from writing extra code. Result is better logging and less cost.
Importance of logging applications
Logging helps in debugging as well. Although debuggers are available but frankly it takes time to debug an application using a debugger. An application can be debugged more easily with few well-placed logging messages. So we can safely say that logging is a very good debugging tool. If logging is done sensibly and wisely, it can provide detailed context for application failures.
In distributed applications (e.g. web/remote applications), the logging is very important. The administrator can read logs to learn about the problems that occurred during some interval.
Java's built-in APIs provide logging options but they are not that flexible. Another option is to use Apache’s open source logging framework called log4j...
Courtesy:- Java-forums.org
- guru's blog
- Login to post comments
