The most important reason is configurability and ease of use. We use logging to record information about the operation of the code. This is not the core functionality of the application, but it is inevitable to have a program that can be operated. There are messages we print out to the log, which can be used by the operating personnel to identify environmental issues. For example, when an IOException is thrown and it gets logged, the operation may look at the logs and identify that a disk got full. They may delete files, or add a new disk and extend the partition. Without the logs, the only information would be that the program does not work.
The logs are also used many times to hunt down bugs. Some of the bugs do not manifest ...