java.lang.Object
org.glassfish.main.jul.cfg.ConfigurationHelper
- Direct Known Subclasses:
FormatterConfigurationHelper,HandlerConfigurationHelper
This is a tool to help with parsing the logging.properties file to configure JUL business objects.
It respects JUL configuration standards, so ie. each formatter knows best how to configure itself, but still can use this helper to parse properties directly to objects instead of plain strings. Helper also supports custom error handlers.
- Author:
- David Matejcek
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceAllows custom error handling (ie. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ConfigurationHelper.LoggingPropertyErrorHandlerLogs an error via theGlassFishLoggingTracer -
Constructor Summary
ConstructorsConstructorDescriptionConfigurationHelper(String prefix, ConfigurationHelper.LoggingPropertyErrorHandler errorHandler) -
Method Summary
Modifier and TypeMethodDescriptiongetBoolean(LogProperty key, Boolean defaultValue) Joinsprefix.key, uses the result to call theLogManager.getProperty(String)and parses the retrieved value.getCharacter(LogProperty key, Character defaultValue) Joinsprefix.key, uses the result to call theLogManager.getProperty(String)and parses the retrieved value.getCharset(LogProperty key, Charset defaultValue) Joinsprefix.key, uses the result to call theLogManager.getProperty(String)and parses the retrieved value.getDateTimeFormatter(LogProperty key, DateTimeFormatter defaultValue) Joinsprefix.key, uses the result to call theLogManager.getProperty(String)and parses the retrieved value.getFile(LogProperty key, File defaultValue) Joinsprefix.key, uses the result to call theLogManager.getProperty(String)and parses the retrieved value.getInteger(LogProperty key, Integer defaultValue) Joinsprefix.key, uses the result to call theLogManager.getProperty(String)and parses the retrieved value.getLevel(LogProperty key, Level defaultValue) Joinsprefix.key, uses the result to call theLogManager.getProperty(String)and parses the retrieved value.getList(LogProperty key, String defaultValue) Joinsprefix.key, uses the result to call theLogManager.getProperty(String)and parses the retrieved value.getNonNegativeInteger(LogProperty key, Integer defaultValue) Joinsprefix.key, uses the result to call theLogManager.getProperty(String)and parses the retrieved value.getString(LogProperty key, String defaultValue) Joinsprefix.key, uses the result to call theLogManager.getProperty(String)and parses the retrieved value.protected voidhandleError(Exception cause, String key, Object property) Calls theConfigurationHelper.LoggingPropertyErrorHandlerset in constructor.protected <T> Tparse(LogProperty key, T defaultValue, Function<String, T> converter) Joinsprefix.key, uses the result to call theLogManager.getProperty(String)and parses the retrieved value.protected <T> TparseOrSupply(LogProperty key, Supplier<T> defaultValueSupplier, Function<String, T> converter) Joinsprefix.key, uses the result to call theLogManager.getProperty(String)and parses the retrieved value.
-
Field Details
-
ERROR_HANDLER_PRINT_TO_STDERR
Logs an error via theGlassFishLoggingTracer
-
-
Constructor Details
-
ConfigurationHelper
public ConfigurationHelper(String prefix, ConfigurationHelper.LoggingPropertyErrorHandler errorHandler) - Parameters:
prefix- Usually a canonical class name without dot.errorHandler-
-
-
Method Details
-
getString
Joinsprefix.key, uses the result to call theLogManager.getProperty(String)and parses the retrieved value. Parsing exceptions are consumed by theConfigurationHelper.LoggingPropertyErrorHandlergiven in constructor.- Parameters:
key- key relative to the prefix given in constructordefaultValue-- Returns:
- parsed
Stringor defaultValue
-
getCharacter
Joinsprefix.key, uses the result to call theLogManager.getProperty(String)and parses the retrieved value. Parsing exceptions are consumed by theConfigurationHelper.LoggingPropertyErrorHandlergiven in constructor.- Parameters:
key- key relative to the prefix given in constructordefaultValue-- Returns:
- parsed
Characteror defaultValue
-
getInteger
Joinsprefix.key, uses the result to call theLogManager.getProperty(String)and parses the retrieved value. Parsing exceptions are consumed by theConfigurationHelper.LoggingPropertyErrorHandlergiven in constructor.- Parameters:
key- key relative to the prefix given in constructordefaultValue-- Returns:
- parsed
Integeror defaultValue
-
getNonNegativeInteger
Joinsprefix.key, uses the result to call theLogManager.getProperty(String)and parses the retrieved value. Parsing exceptions are consumed by theConfigurationHelper.LoggingPropertyErrorHandlergiven in constructor.- Parameters:
key- key relative to the prefix given in constructordefaultValue-- Returns:
- parsed
Integeror defaultValue
-
getBoolean
Joinsprefix.key, uses the result to call theLogManager.getProperty(String)and parses the retrieved value. Parsing exceptions are consumed by theConfigurationHelper.LoggingPropertyErrorHandlergiven in constructor.- Parameters:
key- key relative to the prefix given in constructordefaultValue-- Returns:
- parsed
Booleanor defaultValue
-
getLevel
Joinsprefix.key, uses the result to call theLogManager.getProperty(String)and parses the retrieved value. Parsing exceptions are consumed by theConfigurationHelper.LoggingPropertyErrorHandlergiven in constructor.- Parameters:
key- key relative to the prefix given in constructordefaultValue-- Returns:
- parsed
Levelor defaultValue
-
getFile
Joinsprefix.key, uses the result to call theLogManager.getProperty(String)and parses the retrieved value. Parsing exceptions are consumed by theConfigurationHelper.LoggingPropertyErrorHandlergiven in constructor.- Parameters:
key- key relative to the prefix given in constructordefaultValue-- Returns:
- parsed
Fileor defaultValue
-
getDateTimeFormatter
Joinsprefix.key, uses the result to call theLogManager.getProperty(String)and parses the retrieved value. Parsing exceptions are consumed by theConfigurationHelper.LoggingPropertyErrorHandlergiven in constructor.- Parameters:
key- key relative to the prefix given in constructordefaultValue-- Returns:
- parsed
DateTimeFormatteror defaultValue
-
getCharset
Joinsprefix.key, uses the result to call theLogManager.getProperty(String)and parses the retrieved value. Parsing exceptions are consumed by theConfigurationHelper.LoggingPropertyErrorHandlergiven in constructor.- Parameters:
key- key relative to the prefix given in constructordefaultValue-- Returns:
- parsed
Charsetor defaultValue
-
getList
Joinsprefix.key, uses the result to call theLogManager.getProperty(String)and parses the retrieved value. Parsing exceptions are consumed by theConfigurationHelper.LoggingPropertyErrorHandlergiven in constructor. -
parse
Joinsprefix.key, uses the result to call theLogManager.getProperty(String)and parses the retrieved value. Parsing exceptions are consumed by theConfigurationHelper.LoggingPropertyErrorHandlergiven in constructor.- Type Parameters:
T-- Parameters:
key- key relative to the prefix given in constructordefaultValue-converter- - function used to parse the value or the defaultValue- Returns:
- parsed value or defaultValue
-
parseOrSupply
protected <T> T parseOrSupply(LogProperty key, Supplier<T> defaultValueSupplier, Function<String, T> converter) Joinsprefix.key, uses the result to call theLogManager.getProperty(String)and parses the retrieved value. Parsing exceptions are consumed by theConfigurationHelper.LoggingPropertyErrorHandlergiven in constructor.- Type Parameters:
T-- Parameters:
key- key relative to the prefix given in constructordefaultValueSupplier-converter- - function used to parse the value or the defaultValue- Returns:
- parsed value or defaultValue
-
handleError
Calls theConfigurationHelper.LoggingPropertyErrorHandlerset in constructor.- Parameters:
cause-key-property-- Throws:
RuntimeException- - depends on the implementation of the error handler
-