Package 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
- Author:
- Mark Taylor
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.util.logging.Logger
getLogger(java.lang.String name)
Returns the logger for a given name, retaining a reference to that logger.
-
-
-
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 theLogger
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 usingLogger.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)
-
-