Class Logger.SysLoggerFinder

java.lang.Object
java.lang.System.LoggerFinder
esa.opensf.osfi.Logger.SysLoggerFinder
Enclosing class:
Logger

public static final class Logger.SysLoggerFinder extends System.LoggerFinder
Provides an implementation of System.LoggerFinder. If this class is registered with ServiceLoader, the Java runtime will use the OSFI logger when servicing requests via System.getLogger(String) and similar functions. Messages will only be passed to OSFI if they have at least a minimum level of severity, see getMinLevel().

This registration is not performed by default, and it is not necessary in order to use the OSFI logging system, either directly or via the Logger.sysLoggerToOsfiLog() family of functions. Its main use is to redirect the output of libraries that obtain their loggers directly by calling the mentioned System functions. If needed, this redirection can be enabled by the user code in one of two ways:

  • If using OSFI in the classpath, it is enough to ensure that your JAR contains a text file named "java.lang.System$LoggerFinder" in the folder "META-INF/services" with content "org.esa.opensf.osfi.Logger$SysLoggerFinder". This will point the Java runtime to this implementation.
  • If using OSFI as a (JDK) module: a similar procedure is available, but it requires two steps because unlike with the previous method, the class "providing" the service must be in your own module, so pointing here is not possible. Thus, you need to:
    1. In any public class, create a public static method named provider() that returns a new instance of this class. The return type must be either this class or System.LoggerFinder. The class containing the method has to be public, but it does not need to be in an exported package of the module.
    2. Add the following directive to your module-info.java: "provides java.lang.System.LoggerFinder with your_package.your_class;" where the mentioned class is the one that contains the provider()