Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between java.util.logging.Logger and java.lang.System.Logger

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?

like image 827
Mordechai Avatar asked Jan 29 '20 22:01

Mordechai


People also ask

What is Java Util logger?

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.

Does Java Util logging use Log4j?

The JDK Logging Adapter is a custom implementation of java. util. logging. LogManager that uses Log4j.

Which logger is best for Java?

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.

Why do we use Logger instead of system out Println?

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.


1 Answers

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.

like image 88
Mordechai Avatar answered Sep 24 '22 01:09

Mordechai