java.lang.Object
java.lang.System.LoggerFinder
esa.opensf.osfi.Logger.SysLoggerFinder
- Enclosing class:
- Logger
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:
- 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 orSystem.LoggerFinder. The class containing the method has to be public, but it does not need to be in an exported package of the module. - 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 theprovider()
- In any public class, create a public static method named
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final System.Logger.LevelDefault value forgetMinLevel()if the system property "esa.opensf.osfi.sysLogger.minLevel" is not specified or its value cannot be parsed.static final StringSystem property used to customizegetMinLevel(). -
Constructor Summary
ConstructorsConstructorDescriptionEmpty, but an explicit declaration apparently needed for ServiceLoader. -
Method Summary
Modifier and TypeMethodDescriptionstatic System.Logger.LevelMinimum level used when building the JDK logger wrapping the OSFI log.Methods inherited from class java.lang.System.LoggerFinder
getLocalizedLogger, getLoggerFinder
-
Field Details
-
MIN_LEVEL_PROP
System property used to customizegetMinLevel().- See Also:
-
MIN_LEVEL_DEFAULT
Default value forgetMinLevel()if the system property "esa.opensf.osfi.sysLogger.minLevel" is not specified or its value cannot be parsed. The value of DEBUG means that messages of that level and more severe will be sent to OSFI, while messages of lower severity (TRACE at the time of this writing) will be dropped.
-
-
Constructor Details
-
SysLoggerFinder
public SysLoggerFinder()Empty, but an explicit declaration apparently needed for ServiceLoader.
-
-
Method Details
-
getMinLevel
Minimum level used when building the JDK logger wrapping the OSFI log. May be customized by setting the Java system property "esa.opensf.osfi.sysLogger.minLevel" to one of the names of theSystem.Logger.Levelenumeration.Note: the system property is read only once, the first time this method is called, and the value is then cached for later calls.
- Returns:
- Minimum level of messages to pass to OSFI from the auto-generated JDK logger.
- See Also:
-
getLogger
- Specified by:
getLoggerin classSystem.LoggerFinder
-