Search code examples
javaloggingjava-9

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?


Solution

  • 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.