Class PropertyConfigurator

java.lang.Object
org.jboss.logmanager.PropertyConfigurator
All Implemented Interfaces:
Configurator

public final class PropertyConfigurator extends Object implements Configurator
A configurator which uses a simple property file format.
  • Field Details

    • EMPTY_STRINGS

      private static final String[] EMPTY_STRINGS
    • EXPRESSION_PATTERN

      private static final Pattern EXPRESSION_PATTERN
    • NEW_LINE

      private static final String NEW_LINE
    • config

      private final LogContextConfiguration config
  • Constructor Details

    • PropertyConfigurator

      public PropertyConfigurator()
      Construct an instance.
    • PropertyConfigurator

      public PropertyConfigurator(LogContext context)
      Construct a new instance.
      Parameters:
      context - the log context to be configured
  • Method Details

    • 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 the writeConfiguration(java.io.OutputStream) method also accesses this object directly.
      Returns:
      the log context configuration instance
    • configure

      public void configure(InputStream inputStream) throws IOException
      Configure the logmanager.
      Specified by:
      configure in interface Configurator
      Parameters:
      inputStream - the input stream to read
      Throws:
      IOException - if an error occurs
    • writeConfiguration

      public void writeConfiguration(OutputStream outputStream) 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.
      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 - true if expressions should be written, false if 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

      private static void writePropertyComment(Writer out, String comment) throws 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:
      IOException
    • writeProperty

      private static void writeProperty(Writer out, String name, String value) throws 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:
      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 or null to 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 the PropertyConfigurable.getPropertyValueString(String) to extract the value.
      Parameters:
      out - the print stream to write to.
      prefix - the prefix for the name or null 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:
      IOException
    • toCsvString

      private static String toCsvString(List<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(Properties properties) throws 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
      If the values are written the trimmed values will be written for the above properties.
      Parameters:
      properties - the properties
      Throws:
      IOException - if an error occurs
    • configureLogger

      private void configureLogger(Properties properties, String loggerName)
    • configureFilter

      private boolean configureFilter(Properties properties, String filterName)
    • configureFormatter

      private boolean configureFormatter(Properties properties, String formatterName)
    • configureErrorManager

      private boolean configureErrorManager(Properties properties, String errorManagerName)
    • configureHandler

      private boolean configureHandler(Properties properties, String handlerName)
    • configurePojos

      private boolean configurePojos(Properties properties, String pojoName)
    • configureProperties

      private void configureProperties(Properties properties, PropertyConfigurable configurable, String prefix)
    • getKey

      private static String getKey(String prefix, String objectName)
    • getKey

      private static String getKey(String prefix, String objectName, String key)
    • getStringProperty

      private static String getStringProperty(Properties properties, String key)
    • getStringProperty

      private static String getStringProperty(Properties properties, String key, boolean trim)
    • getStringCsvArray

      private static String[] getStringCsvArray(Properties properties, String key)
    • getStringCsvList

      private static List<String> getStringCsvList(Properties properties, String key)
    • writeValue

      private static void writeValue(Appendable out, String value) throws IOException
      Throws:
      IOException
    • writeKey

      private static void writeKey(Appendable out, String key) throws IOException
      Throws:
      IOException
    • writeSanitized

      private static void writeSanitized(Appendable out, String string, boolean escapeSpaces) throws IOException
      Throws:
      IOException
    • printError

      static void printError(String msg)
      Prints the message to stderr.
      Parameters:
      msg - the message to print
    • printError

      static void printError(String format, Object... args)
      Prints the message to stderr.
      Parameters:
      format - the format of the message
      args - the format arguments
    • safeClose

      private static void safeClose(Closeable stream)