Adding logging ability
Let's start with using the logging API in Java to log messages to the console. As an example, we want to be able to log some sample messages during the application start and completion.
What we'd typically do in Java 8 or earlier is just import the necessary logging classes and start using the logging APIs. That is, the Logger
class from the java.util.logging
package. However, as we've learned in the previous chapter, there's an additional step in Java 9. Using the logging APIs directly will result in a compilation error. That's because the logging APIs aren't available in the java.base
module. We've seen that the best way to search for a module is using the --list-modules
parameter to the java
command. Let's run that and see if we find a module related to logging:
$ java --list-modules
...
java.jnlp@9
java.logging@9
java.management@9
java.naming@9
java.prefs@9
As you can see, there's a module called java.logging
. That looks promising! The next step is to see if that...