Module io.jstach.rainbowgum.jdk


module io.jstach.rainbowgum.jdk
Rainbow Gum JDK components. This module provides special integration and adapters for the built-in JDK logging facilities. The impetus for this is these logging facilities can be used very early in the JDK boot processes well before logging has fully initialized. Furthermore the JDK itself recommends that heavy initialization should not happen.

The integration will make sure that neither the System.Logger or java.util.logging will initialize Rainbow Gum too early by queueing the events. When a Rainbow Gum initializes and set as global the events will be replayed. If the events level are equal to System.Logger.Level.ERROR and a normal Rainbow Gum has not been bound the messages will be printed to System.err. The idea is something catastrophic has happened that will probably cause Rainbow Gum to never load and thus never replay the events and you will not be able to figure out what happened.

SLF4J does provide an adapter/bridge for the System.Logger (org.slf4j:slf4j-jdk-platform-logging) but its use may cause Rainbow Gum to initialize too early. However that maybe desirable if:

  • You are sure that Rainbow Gum can initialize early
  • Your application uses System.Logger (the SLF4J adapter will initialize Rainbow Gum on Sytem.Logger usage if using io.jstach.rainbowgum.slf4j module)
An alternative to using the SLF4J bridge if eager initialization is desired is to set a System property with "logging.systemlogger.intialize" to the values in RainbowGumSystemLoggerFinder.InitOption. however that maybe difficult if one cannot set system properties before loading logging.

To disable installation of the java.util.logging handler set the property: "logging.jul.disable" to true. Alternatively if in a custom modular environment using jlink and the module java.logging is not included the handler will not be installed. Furthermore the module java.logging is not required and thus jlink might not automatically include it as it is requires static.

NOTE: While the JDK System.Logger is good for low level libraries it's API (and Rainbow Gum implementation) is not designed for performance. For applications and frameworks that do a lot of logging the SLF4J facade is the preferred choice.

Because the logger names of System.Logger and JUL are far less likely to be actual class names and could be anything (unlike SLF4J which encourages class names and static loggers) Rainbow Gum does not cache System.Loggers.