Java 9 introduced a new logger, namely java.lang.System.Logger
but we always had java.util.logging.Logger
.
What's new with this logger and how it is better?
A Logger object is used to log messages for a specific system or application component. Loggers are normally named, using a hierarchical dot-separated namespace. Logger names can be arbitrary strings, but they should normally be based on the package name or class name of the logged component, such as java.net or javax.
The JDK Logging Adapter is a custom implementation of java. util. logging. LogManager that uses Log4j.
One of the most popular solutions for the Java world is the Apache Log4j 2 framework. Maintained by the Apache Foundation, Log4j 2 is an improvement on the original Log4j, which was the most popular logging framework in Java for many years.
If you are running a Java program in Linux or any UNIX-based system, Log4j or SLF4j or any other logging framework offers a lot more features, flexibility, and improvement on message quality, which is not possible using the System. out. println() statement.
While there might be subtle differences between them, the most important difference is that System.Logger
(in java.base
module) is a facade, while java.util.logging.Logger
(in java.logging
) is an implementation.
The core idea behind this is for library authors to write dependency free logging in their code and let every user of that library provide their favorite implementation. It also means your whole application will use the same logging framework instead of having to tune the logger of each and every library in your codebase.
Since JDK 9 it is possible to not have java.logging
in the module-graph, which really frees you to use any implementation you wish without even having useless packages in the JDK image. In case java.logging
is present, it's used as the default backend unless a different backend is present. If no backend is present, it will just print to System.err
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With