uk.ac.starlink.util

## Class LogUtils

- java.lang.Object
- - uk.ac.starlink.util.LogUtils

-     public class LogUtils
      extends java.lang.Object

  Utilities for working with logging.
  Since:
    20 Jul 2022

- - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static java.util.logging.Logger` | `getLogger(java.lang.String name)` Returns the logger for a given name, retaining a reference to that logger.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### getLogger

          public static java.util.logging.Logger getLogger(java.lang.String name)

      Returns the logger for a given name, retaining a reference to that logger.

      The output is the same as `Logger.getLogger(java.lang.String)`, for which it is a drop-in replacement, but because a reference is retained by this class, the returned object will not be subsequently garbage collected; as noted in the `Logger` javadocs:

      > "It is important to note that the Logger returned by one of the `getLogger` factory methods may be garbage collected at any time if a strong reference to the Logger is not kept."

      So if you want to modify one of the loggers in the logging hierarchy, you can do it like:

              LogUtils.getLogger("a.b.c").setLevel(Level.WARNING)

      If you make the corresponding call using `Logger.getLogger`, the logger may have been garbage collected and recreated without the desired configuration by the time it's actually used to log something.
      Parameters:
        `name` - logger name
      Returns:
        logger
      See Also:
        `Logger.getLogger(java.lang.String)`