34
Logging
Most real world applications will log information as they execute. Logging is a useful mechanism for outputting the state and behavior of a program as it executes so that it is possible to “manually debug” the program if an issue is encountered.
I use the words “manually debug” here, because typically you will not be able to debug programs if they are being executed by a third party, or in a production environment, but you still need some way of finding out what the program is doing if an issue occurs.
Logging can be used for outputting error information such as stack traces, or any other general information that may be useful when attempting to determine the behavior of a program.
Java includes a logging API that is suitable for most needs. There are also several other open source logging libraries available for more advanced needs. This chapter will limit itself to the logging API provided natively by Java.