Class JdkLoggerConfig
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 (theLoggerConfig
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 theLogger
API itself. - This API adds the @Nullable annotation to parameters and return values where appropriate.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addHandler
(Handler handler) static JdkLoggerConfig
Returns a configuration instance suitable for configuring the logger of the specified class.static JdkLoggerConfig
Returns a configuration instance suitable for configuring a logger with the same name.SeeLogger.getFilter()
.Handler[]
SeeLogger.getHandlers()
.getLevel()
SeeLogger.getLevel()
.getName()
SeeLogger.getName()
.static JdkLoggerConfig
getPackageConfig
(Class<?> clazz) Returns a configuration instance suitable for configuring loggers in the same package as the specified class.SeeLogger.getParent()
.boolean
void
removeHandler
(Handler handler) void
void
void
setUseParentHandlers
(boolean useParentHandlers)
-
Method Details
-
getConfig
Returns a configuration instance suitable for configuring the logger of the specified class.This method obtains and wraps the underlying logger for the given class, retaining a strong reference and making it safe to use for persistent configuration changes.
- Parameters:
clazz
- the class whose logger is to be configured via this API.
-
getPackageConfig
Returns a configuration instance suitable for configuring loggers in the same package as the specified class.This method obtains and wraps the underlying logger for the given package, retaining a string reference and making it safe to use for persistent configuration changes.
- Parameters:
clazz
- a class defining the package for which logger configuration should occur.
-
getConfig
Returns a configuration instance suitable for configuring a logger with the same name.This method obtains and wraps the underlying logger with the given name, retaining a strong reference and making it safe to use for persistent configuration changes. Note that as it makes very little sense to have a logger configuration object which wraps (and hides) an anonymous logger instance,
null
names are disallowed.- Parameters:
name
- the name of the logger to be configured via this API.
-
getResourceBundle
-
getResourceBundleName
-
setFilter
- Throws:
SecurityException
-
getFilter
SeeLogger.getFilter()
. -
setLevel
- Throws:
SecurityException
-
getLevel
SeeLogger.getLevel()
. -
getName
SeeLogger.getName()
. -
addHandler
- Throws:
SecurityException
-
removeHandler
- Throws:
SecurityException
-
getHandlers
SeeLogger.getHandlers()
. -
setUseParentHandlers
public void setUseParentHandlers(boolean useParentHandlers) -
getUseParentHandlers
public boolean getUseParentHandlers() -
getParent
SeeLogger.getParent()
.
-