Using logging
In your own code, you may want to display messages in the console while the program runs. These messages may be to inform you that an exception has been caught or record any other event that happens during the program’s execution. While you can write to the console using System.out.print
, println
, or my favorite, printf
, do not. If the application is console-based, then these statements will appear with the console user interface. For GUI or web applications, the console may or may not be visible. Once the program goes into production, the end user may be confused or overwhelmed by the messages you display in the console.
The solution is logging. This allows you to write log messages to the console, a file, or a database, or even send them to yourself in an email. We will only look at the console or a file. Java has a logging framework, found in java.util.logging
. We will also look at one of the external logging frameworks from the Apache Foundation, called...