Class JdkLoggerConfig

java.lang.Object
google.registry.util.JdkLoggerConfig

@CheckReturnValue public final class JdkLoggerConfig extends Object
An adapter for the configuration specific aspects of a JDK logger which retains a strong reference to the corresponding underlying logger to prevent accidental garbage collection. This class is needed to help avoid bugs caused by the premature garbage collection of logger instances (which are only weakly referenced when returned by Logger.getLogger(java.lang.String)).

It is important to note that while this class is in the Flogger package, it's not actually a part of the core logging API and will only have any effect if you are using a JDK based logging backend. In general Flogger avoids the issue of defining how logging is configured, but the issues around weakly referenced JDK loggers are so common, and so hard to debug, it was felt necessary to provide an easily available solution for that problem.

All methods in this API simply delegate to the equivalent Logger method without any additional checking.

A small number of small differences exist between using this class and using a Logger instance directly, but these are deliberate and seek to avoid misuse.

  • The LoggerConfig API has no "setParent()" method (this should never be called by application code anyway).
  • It is not possible to obtain a LoggerConfig instance for an anonymous logger (the LoggerConfig API hides the underlying logger, so it would be impossible to do any logging with such an object). If you are using an anonymous logger then you must continue to configure it via the Logger API itself.
  • This API adds the @Nullable annotation to parameters and return values where appropriate.