public class LogUtils extends Object
Modifier and Type | Method and Description |
---|---|
static Logger |
getLogger(String name)
Returns the logger for a given name, retaining a reference to
that logger.
|
public static Logger getLogger(String name)
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.name
- logger nameLogger.getLogger(java.lang.String)
Copyright © 2024 Central Laboratory of the Research Councils. All Rights Reserved.