Package org.jboss.logmanager
Class PropertyConfigurator
- java.lang.Object
-
- org.jboss.logmanager.PropertyConfigurator
-
- All Implemented Interfaces:
Configurator
public final class PropertyConfigurator extends java.lang.Object implements Configurator
A configurator which uses a simple property file format.
-
-
Field Summary
Fields Modifier and Type Field Description private LogContextConfigurationconfigprivate static java.lang.String[]EMPTY_STRINGSprivate static java.util.regex.PatternEXPRESSION_PATTERNprivate static java.lang.StringNEW_LINE-
Fields inherited from interface org.jboss.logmanager.Configurator
ATTACHMENT_KEY
-
-
Constructor Summary
Constructors Constructor Description PropertyConfigurator()Construct an instance.PropertyConfigurator(LogContext context)Construct a new instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidconfigure(java.io.InputStream inputStream)Configure the logmanager.voidconfigure(java.util.Properties properties)Configure the log manager from the given properties.private booleanconfigureErrorManager(java.util.Properties properties, java.lang.String errorManagerName)private booleanconfigureFilter(java.util.Properties properties, java.lang.String filterName)private booleanconfigureFormatter(java.util.Properties properties, java.lang.String formatterName)private booleanconfigureHandler(java.util.Properties properties, java.lang.String handlerName)private voidconfigureLogger(java.util.Properties properties, java.lang.String loggerName)private booleanconfigurePojos(java.util.Properties properties, java.lang.String pojoName)private voidconfigureProperties(java.util.Properties properties, PropertyConfigurable configurable, java.lang.String prefix)private static java.lang.StringgetKey(java.lang.String prefix, java.lang.String objectName)private static java.lang.StringgetKey(java.lang.String prefix, java.lang.String objectName, java.lang.String key)LogContextConfigurationgetLogContextConfiguration()Get the log context configuration.private static java.lang.String[]getStringCsvArray(java.util.Properties properties, java.lang.String key)private static java.util.List<java.lang.String>getStringCsvList(java.util.Properties properties, java.lang.String key)private static java.lang.StringgetStringProperty(java.util.Properties properties, java.lang.String key)private static java.lang.StringgetStringProperty(java.util.Properties properties, java.lang.String key, boolean trim)(package private) static voidprintError(java.lang.String msg)Prints the message to stderr.(package private) static voidprintError(java.lang.String format, java.lang.Object... args)Prints the message to stderr.private static voidsafeClose(java.io.Closeable stream)private static java.lang.StringtoCsvString(java.util.List<java.lang.String> names)Parses the list and creates a comma delimited string of the names.voidwriteConfiguration(java.io.OutputStream outputStream)Writes the current configuration to the output stream.voidwriteConfiguration(java.io.OutputStream outputStream, boolean writeExpressions)Writes the current configuration to the output stream.private static voidwriteErrorManagerConfiguration(java.io.Writer out, ErrorManagerConfiguration errorManager, boolean writeExpressions)private static voidwriteFilterConfiguration(java.io.Writer out, FilterConfiguration filter, boolean writeExpressions)private static voidwriteFormatterConfiguration(java.io.Writer out, FormatterConfiguration formatter, boolean writeExpressions)private voidwriteHandlerConfiguration(java.io.Writer out, HandlerConfiguration handler, java.util.Set<java.lang.String> implicitHandlers, java.util.Set<java.lang.String> implicitFilters, java.util.Set<java.lang.String> implicitFormatters, java.util.Set<java.lang.String> implicitErrorManagers, boolean writeExpressions)private static voidwriteKey(java.lang.Appendable out, java.lang.String key)private voidwriteLoggerConfiguration(java.io.Writer out, LoggerConfiguration logger, java.util.Set<java.lang.String> implicitHandlers, java.util.Set<java.lang.String> implicitFilters, boolean writeExpressions)private static voidwritePojoConfiguration(java.io.Writer out, PojoConfiguration pojo, boolean writeExpressions)private static voidwriteProperties(java.io.Writer out, java.lang.String prefix, PropertyConfigurable propertyConfigurable, boolean writeExpression)Writes a collection of properties to the print stream.private static voidwriteProperty(java.io.Writer out, java.lang.String name, java.lang.String value)Writes a property to the print stream.private static voidwriteProperty(java.io.Writer out, java.lang.String prefix, java.lang.String name, java.lang.String value)Writes a property to the print stream.private static voidwritePropertyComment(java.io.Writer out, java.lang.String comment)Writes a comment to the print stream.private static voidwriteSanitized(java.lang.Appendable out, java.lang.String string, boolean escapeSpaces)private static voidwriteValue(java.lang.Appendable out, java.lang.String value)
-
-
-
Field Detail
-
EMPTY_STRINGS
private static final java.lang.String[] EMPTY_STRINGS
-
EXPRESSION_PATTERN
private static final java.util.regex.Pattern EXPRESSION_PATTERN
-
NEW_LINE
private static final java.lang.String NEW_LINE
-
config
private final LogContextConfiguration config
-
-
Constructor Detail
-
PropertyConfigurator
public PropertyConfigurator()
Construct an instance.
-
PropertyConfigurator
public PropertyConfigurator(LogContext context)
Construct a new instance.- Parameters:
context- the log context to be configured
-
-
Method Detail
-
getLogContextConfiguration
public LogContextConfiguration getLogContextConfiguration()
Get the log context configuration. WARNING: this instance is not thread safe in any way. The returned object should never be used from more than one thread at a time; furthermore thewriteConfiguration(java.io.OutputStream)method also accesses this object directly.- Returns:
- the log context configuration instance
-
configure
public void configure(java.io.InputStream inputStream) throws java.io.IOExceptionConfigure the logmanager.- Specified by:
configurein interfaceConfigurator- Parameters:
inputStream- the input stream to read- Throws:
java.io.IOException- if an error occurs
-
writeConfiguration
public void writeConfiguration(java.io.OutputStream outputStream) throws java.io.IOExceptionWrites the current configuration to the output stream. Note: the output stream will be closed.- Parameters:
outputStream- the output stream to write to.- Throws:
java.io.IOException- if an error occurs while writing the configuration.
-
writeConfiguration
public void writeConfiguration(java.io.OutputStream outputStream, boolean writeExpressions) throws java.io.IOExceptionWrites the current configuration to the output stream. Note: the output stream will be closed.- Parameters:
outputStream- the output stream to write to.writeExpressions-trueif expressions should be written,falseif the resolved value should be written- Throws:
java.io.IOException- if an error occurs while writing the configuration.
-
writeLoggerConfiguration
private void writeLoggerConfiguration(java.io.Writer out, LoggerConfiguration logger, java.util.Set<java.lang.String> implicitHandlers, java.util.Set<java.lang.String> implicitFilters, boolean writeExpressions) throws java.io.IOException- Throws:
java.io.IOException
-
writeHandlerConfiguration
private void writeHandlerConfiguration(java.io.Writer out, HandlerConfiguration handler, java.util.Set<java.lang.String> implicitHandlers, java.util.Set<java.lang.String> implicitFilters, java.util.Set<java.lang.String> implicitFormatters, java.util.Set<java.lang.String> implicitErrorManagers, boolean writeExpressions) throws java.io.IOException- Throws:
java.io.IOException
-
writeFilterConfiguration
private static void writeFilterConfiguration(java.io.Writer out, FilterConfiguration filter, boolean writeExpressions) throws java.io.IOException- Throws:
java.io.IOException
-
writeFormatterConfiguration
private static void writeFormatterConfiguration(java.io.Writer out, FormatterConfiguration formatter, boolean writeExpressions) throws java.io.IOException- Throws:
java.io.IOException
-
writeErrorManagerConfiguration
private static void writeErrorManagerConfiguration(java.io.Writer out, ErrorManagerConfiguration errorManager, boolean writeExpressions) throws java.io.IOException- Throws:
java.io.IOException
-
writePojoConfiguration
private static void writePojoConfiguration(java.io.Writer out, PojoConfiguration pojo, boolean writeExpressions) throws java.io.IOException- Throws:
java.io.IOException
-
writePropertyComment
private static void writePropertyComment(java.io.Writer out, java.lang.String comment) throws java.io.IOExceptionWrites a comment to the print stream. Prepends the comment with a#.- Parameters:
out- the print stream to write to.comment- the comment to write.- Throws:
java.io.IOException
-
writeProperty
private static void writeProperty(java.io.Writer out, java.lang.String name, java.lang.String value) throws java.io.IOExceptionWrites a property to the print stream.- Parameters:
out- the print stream to write to.name- the name of the property.value- the value of the property.- Throws:
java.io.IOException
-
writeProperty
private static void writeProperty(java.io.Writer out, java.lang.String prefix, java.lang.String name, java.lang.String value) throws java.io.IOExceptionWrites a property to the print stream.- Parameters:
out- the print stream to write to.prefix- the prefix for the name ornullto use no prefix.name- the name of the property.value- the value of the property.- Throws:
java.io.IOException
-
writeProperties
private static void writeProperties(java.io.Writer out, java.lang.String prefix, PropertyConfigurable propertyConfigurable, boolean writeExpression) throws java.io.IOExceptionWrites a collection of properties to the print stream. Uses thePropertyConfigurable.getPropertyValueString(String)to extract the value.- Parameters:
out- the print stream to write to.prefix- the prefix for the name ornullto use no prefix.propertyConfigurable- the configuration to extract the property value from.writeExpression-trueif expressions should be written,falseif the resolved value should be written- Throws:
java.io.IOException
-
toCsvString
private static java.lang.String toCsvString(java.util.List<java.lang.String> names)
Parses the list and creates a comma delimited string of the names. Notes: empty names are ignored.- Parameters:
names- the names to process.- Returns:
- a comma delimited list of the names.
-
configure
public void configure(java.util.Properties properties) throws java.io.IOExceptionConfigure the log manager from the given properties. The following values read in from a configuration will be trimmed of prefixed and trailing whitespace:- logger.NAME.filter
- logger.NAME.level
- logger.NAME.useParentHandlers
- handler.NAME.filter
- handler.NAME.formatter
- handler.NAME.level
- handler.NAME.encoding
- handler.NAME.errorManager
writtenthe trimmed values will be written for the above properties.- Parameters:
properties- the properties- Throws:
java.io.IOException- if an error occurs
-
configureLogger
private void configureLogger(java.util.Properties properties, java.lang.String loggerName)
-
configureFilter
private boolean configureFilter(java.util.Properties properties, java.lang.String filterName)
-
configureFormatter
private boolean configureFormatter(java.util.Properties properties, java.lang.String formatterName)
-
configureErrorManager
private boolean configureErrorManager(java.util.Properties properties, java.lang.String errorManagerName)
-
configureHandler
private boolean configureHandler(java.util.Properties properties, java.lang.String handlerName)
-
configurePojos
private boolean configurePojos(java.util.Properties properties, java.lang.String pojoName)
-
configureProperties
private void configureProperties(java.util.Properties properties, PropertyConfigurable configurable, java.lang.String prefix)
-
getKey
private static java.lang.String getKey(java.lang.String prefix, java.lang.String objectName)
-
getKey
private static java.lang.String getKey(java.lang.String prefix, java.lang.String objectName, java.lang.String key)
-
getStringProperty
private static java.lang.String getStringProperty(java.util.Properties properties, java.lang.String key)
-
getStringProperty
private static java.lang.String getStringProperty(java.util.Properties properties, java.lang.String key, boolean trim)
-
getStringCsvArray
private static java.lang.String[] getStringCsvArray(java.util.Properties properties, java.lang.String key)
-
getStringCsvList
private static java.util.List<java.lang.String> getStringCsvList(java.util.Properties properties, java.lang.String key)
-
writeValue
private static void writeValue(java.lang.Appendable out, java.lang.String value) throws java.io.IOException- Throws:
java.io.IOException
-
writeKey
private static void writeKey(java.lang.Appendable out, java.lang.String key) throws java.io.IOException- Throws:
java.io.IOException
-
writeSanitized
private static void writeSanitized(java.lang.Appendable out, java.lang.String string, boolean escapeSpaces) throws java.io.IOException- Throws:
java.io.IOException
-
printError
static void printError(java.lang.String msg)
Prints the message to stderr.- Parameters:
msg- the message to print
-
printError
static void printError(java.lang.String format, java.lang.Object... args)Prints the message to stderr.- Parameters:
format- the format of the messageargs- the format arguments
-
safeClose
private static void safeClose(java.io.Closeable stream)
-
-