# Class LogUtils

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

public class LogUtils extends Object
Utilities for working with logging.

Since:
  20 Jul 2022
Author:
  Mark Taylor

## Method Summary

Modifier and Type
Method
Description
`static Logger`
`getLogger(String name)`
Returns the logger for a given name, retaining a reference to that logger.

### Methods inherited from class Object

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

## Method Details

### getLogger

public static Logger getLogger(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(String)`