Class PropertyConfigurator
java.lang.Object
org.jboss.logmanager.PropertyConfigurator
- All Implemented Interfaces:
Configurator
A configurator which uses a simple property file format.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final LogContextConfigurationprivate static final String[]private static final Patternprivate static final StringFields inherited from interface Configurator
ATTACHMENT_KEY -
Constructor Summary
ConstructorsConstructorDescriptionConstruct an instance.PropertyConfigurator(LogContext context) Construct a new instance. -
Method Summary
Modifier and TypeMethodDescriptionvoidconfigure(InputStream inputStream) Configure the logmanager.voidconfigure(Properties properties) Configure the log manager from the given properties.private booleanconfigureErrorManager(Properties properties, String errorManagerName) private booleanconfigureFilter(Properties properties, String filterName) private booleanconfigureFormatter(Properties properties, String formatterName) private booleanconfigureHandler(Properties properties, String handlerName) private voidconfigureLogger(Properties properties, String loggerName) private booleanconfigurePojos(Properties properties, String pojoName) private voidconfigureProperties(Properties properties, PropertyConfigurable configurable, String prefix) private static Stringprivate static StringGet the log context configuration.private static String[]getStringCsvArray(Properties properties, String key) getStringCsvList(Properties properties, String key) private static StringgetStringProperty(Properties properties, String key) private static StringgetStringProperty(Properties properties, String key, boolean trim) (package private) static voidprintError(String msg) Prints the message to stderr.(package private) static voidprintError(String format, Object... args) Prints the message to stderr.private static voidprivate static StringtoCsvString(List<String> names) Parses the list and creates a comma delimited string of the names.voidwriteConfiguration(OutputStream outputStream) Writes the current configuration to the output stream.voidwriteConfiguration(OutputStream outputStream, boolean writeExpressions) Writes the current configuration to the output stream.private static voidwriteErrorManagerConfiguration(Writer out, ErrorManagerConfiguration errorManager, boolean writeExpressions) private static voidwriteFilterConfiguration(Writer out, FilterConfiguration filter, boolean writeExpressions) private static voidwriteFormatterConfiguration(Writer out, FormatterConfiguration formatter, boolean writeExpressions) private voidwriteHandlerConfiguration(Writer out, HandlerConfiguration handler, Set<String> implicitHandlers, Set<String> implicitFilters, Set<String> implicitFormatters, Set<String> implicitErrorManagers, boolean writeExpressions) private static voidwriteKey(Appendable out, String key) private voidwriteLoggerConfiguration(Writer out, LoggerConfiguration logger, Set<String> implicitHandlers, Set<String> implicitFilters, boolean writeExpressions) private static voidwritePojoConfiguration(Writer out, PojoConfiguration pojo, boolean writeExpressions) private static voidwriteProperties(Writer out, String prefix, PropertyConfigurable propertyConfigurable, boolean writeExpression) Writes a collection of properties to the print stream.private static voidwriteProperty(Writer out, String name, String value) Writes a property to the print stream.private static voidwriteProperty(Writer out, String prefix, String name, String value) Writes a property to the print stream.private static voidwritePropertyComment(Writer out, String comment) Writes a comment to the print stream.private static voidwriteSanitized(Appendable out, String string, boolean escapeSpaces) private static voidwriteValue(Appendable out, String value)
-
Field Details
-
EMPTY_STRINGS
-
EXPRESSION_PATTERN
-
NEW_LINE
-
config
-
-
Constructor Details
-
PropertyConfigurator
public PropertyConfigurator()Construct an instance. -
PropertyConfigurator
Construct a new instance.- Parameters:
context- the log context to be configured
-
-
Method Details
-
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
Configure the logmanager.- Specified by:
configurein interfaceConfigurator- Parameters:
inputStream- the input stream to read- Throws:
IOException- if an error occurs
-
writeConfiguration
Writes the current configuration to the output stream. Note: the output stream will be closed.- Parameters:
outputStream- the output stream to write to.- Throws:
IOException- if an error occurs while writing the configuration.
-
writeConfiguration
public void writeConfiguration(OutputStream outputStream, boolean writeExpressions) throws IOException Writes 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:
IOException- if an error occurs while writing the configuration.
-
writeLoggerConfiguration
private void writeLoggerConfiguration(Writer out, LoggerConfiguration logger, Set<String> implicitHandlers, Set<String> implicitFilters, boolean writeExpressions) throws IOException - Throws:
IOException
-
writeHandlerConfiguration
private void writeHandlerConfiguration(Writer out, HandlerConfiguration handler, Set<String> implicitHandlers, Set<String> implicitFilters, Set<String> implicitFormatters, Set<String> implicitErrorManagers, boolean writeExpressions) throws IOException - Throws:
IOException
-
writeFilterConfiguration
private static void writeFilterConfiguration(Writer out, FilterConfiguration filter, boolean writeExpressions) throws IOException - Throws:
IOException
-
writeFormatterConfiguration
private static void writeFormatterConfiguration(Writer out, FormatterConfiguration formatter, boolean writeExpressions) throws IOException - Throws:
IOException
-
writeErrorManagerConfiguration
private static void writeErrorManagerConfiguration(Writer out, ErrorManagerConfiguration errorManager, boolean writeExpressions) throws IOException - Throws:
IOException
-
writePojoConfiguration
private static void writePojoConfiguration(Writer out, PojoConfiguration pojo, boolean writeExpressions) throws IOException - Throws:
IOException
-
writePropertyComment
Writes 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:
IOException
-
writeProperty
Writes 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:
IOException
-
writeProperty
private static void writeProperty(Writer out, String prefix, String name, String value) throws IOException Writes 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:
IOException
-
writeProperties
private static void writeProperties(Writer out, String prefix, PropertyConfigurable propertyConfigurable, boolean writeExpression) throws IOException Writes 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:
IOException
-
toCsvString
-
configure
Configure 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:
IOException- if an error occurs
-
configureLogger
-
configureFilter
-
configureFormatter
-
configureErrorManager
-
configureHandler
-
configurePojos
-
configureProperties
private void configureProperties(Properties properties, PropertyConfigurable configurable, String prefix) -
getKey
-
getKey
-
getStringProperty
-
getStringProperty
-
getStringCsvArray
-
getStringCsvList
-
writeValue
- Throws:
IOException
-
writeKey
- Throws:
IOException
-
writeSanitized
private static void writeSanitized(Appendable out, String string, boolean escapeSpaces) throws IOException - Throws:
IOException
-
printError
Prints the message to stderr.- Parameters:
msg- the message to print
-
printError
-
safeClose
-