What is Platform Logging API in Java 9?


In Java 9, Platform Logging API can be used to log messages with a service interface for consumers of those messages. An implementation of LoggerFinder has been loaded with the help of java.util.ServiceLoader API by using System ClassLoader. Based on this implementation, an application can plug in its own external logging backend without configuring java.util.logging.

We can pass a class name or module to LoggerFinder so that it knows which logger to return.

public class MyLoggerFinder extends LoggerFinder {
   @Override
   public Logger getLogger(String name, Module module) {
      // return a logger depends on name/module
   }
}

If no concrete implementation can be found, then a default LoggerFinder implementation has been used. We obtain loggers that have created from LoggerFinder by using factory methods of the System class.

public class System {
   System.Logger getLogger(String name) {
   }
   System.Logger getLogger(String name, ResourceBundle bundle) {
   }
}

Updated on: 11-Mar-2020

188 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements