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 LogContextConfiguration
config
private static java.lang.String[]
EMPTY_STRINGS
private static java.util.regex.Pattern
EXPRESSION_PATTERN
private static java.lang.String
NEW_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 void
configure(java.io.InputStream inputStream)
Configure the logmanager.void
configure(java.util.Properties properties)
Configure the log manager from the given properties.private boolean
configureErrorManager(java.util.Properties properties, java.lang.String errorManagerName)
private boolean
configureFilter(java.util.Properties properties, java.lang.String filterName)
private boolean
configureFormatter(java.util.Properties properties, java.lang.String formatterName)
private boolean
configureHandler(java.util.Properties properties, java.lang.String handlerName)
private void
configureLogger(java.util.Properties properties, java.lang.String loggerName)
private boolean
configurePojos(java.util.Properties properties, java.lang.String pojoName)
private void
configureProperties(java.util.Properties properties, PropertyConfigurable configurable, java.lang.String prefix)
private static java.lang.String
getKey(java.lang.String prefix, java.lang.String objectName)
private static java.lang.String
getKey(java.lang.String prefix, java.lang.String objectName, java.lang.String key)
LogContextConfiguration
getLogContextConfiguration()
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.String
getStringProperty(java.util.Properties properties, java.lang.String key)
private static java.lang.String
getStringProperty(java.util.Properties properties, java.lang.String key, boolean trim)
(package private) static void
printError(java.lang.String msg)
Prints the message to stderr.(package private) static void
printError(java.lang.String format, java.lang.Object... args)
Prints the message to stderr.private static void
safeClose(java.io.Closeable stream)
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.void
writeConfiguration(java.io.OutputStream outputStream)
Writes the current configuration to the output stream.void
writeConfiguration(java.io.OutputStream outputStream, boolean writeExpressions)
Writes the current configuration to the output stream.private static void
writeErrorManagerConfiguration(java.io.Writer out, ErrorManagerConfiguration errorManager, boolean writeExpressions)
private static void
writeFilterConfiguration(java.io.Writer out, FilterConfiguration filter, boolean writeExpressions)
private static void
writeFormatterConfiguration(java.io.Writer out, FormatterConfiguration formatter, boolean writeExpressions)
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)
private static void
writeKey(java.lang.Appendable out, java.lang.String key)
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)
private static void
writePojoConfiguration(java.io.Writer out, PojoConfiguration pojo, boolean writeExpressions)
private static void
writeProperties(java.io.Writer out, java.lang.String prefix, PropertyConfigurable propertyConfigurable, boolean writeExpression)
Writes a collection of properties to the print stream.private static void
writeProperty(java.io.Writer out, java.lang.String name, java.lang.String value)
Writes a property to the print stream.private static void
writeProperty(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 void
writePropertyComment(java.io.Writer out, java.lang.String comment)
Writes a comment to the print stream.private static void
writeSanitized(java.lang.Appendable out, java.lang.String string, boolean escapeSpaces)
private static void
writeValue(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.IOException
Configure the logmanager.- Specified by:
configure
in 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.IOException
Writes 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.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
-true
if expressions should be written,false
if 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.IOException
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:
java.io.IOException
-
writeProperty
private static void writeProperty(java.io.Writer out, java.lang.String name, java.lang.String value) throws java.io.IOException
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:
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.IOException
Writes a property to the print stream.- Parameters:
out
- the print stream to write to.prefix
- the prefix for the name ornull
to 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.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 ornull
to use no prefix.propertyConfigurable
- the configuration to extract the property value from.writeExpression
-true
if expressions should be written,false
if 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.IOException
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
written
the 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)
-
-