Search in sources :

Example 6 with PatternFormatter

use of org.apache.logging.log4j.core.pattern.PatternFormatter in project spring-boot by spring-projects.

the class ColorConverter method newInstance.

/**
	 * Creates a new instance of the class. Required by Log4J2.
	 * @param config the configuration
	 * @param options the options
	 * @return a new instance, or {@code null} if the options are invalid
	 */
public static ColorConverter newInstance(Configuration config, String[] options) {
    if (options.length < 1) {
        LOGGER.error("Incorrect number of options on style. " + "Expected at least 1, received {}", options.length);
        return null;
    }
    if (options[0] == null) {
        LOGGER.error("No pattern supplied on style");
        return null;
    }
    PatternParser parser = PatternLayout.createPatternParser(config);
    List<PatternFormatter> formatters = parser.parse(options[0]);
    AnsiElement element = (options.length == 1 ? null : ELEMENTS.get(options[1]));
    return new ColorConverter(formatters, element);
}
Also used : PatternParser(org.apache.logging.log4j.core.pattern.PatternParser) PatternFormatter(org.apache.logging.log4j.core.pattern.PatternFormatter) AnsiElement(org.springframework.boot.ansi.AnsiElement)

Aggregations

PatternFormatter (org.apache.logging.log4j.core.pattern.PatternFormatter)6 PatternParser (org.apache.logging.log4j.core.pattern.PatternParser)3 AnsiElement (org.springframework.boot.ansi.AnsiElement)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 SortedMap (java.util.SortedMap)1 TreeMap (java.util.TreeMap)1 SimpleBindings (javax.script.SimpleBindings)1 Configuration (org.apache.logging.log4j.core.config.Configuration)1 DefaultConfiguration (org.apache.logging.log4j.core.config.DefaultConfiguration)1 Message (org.apache.logging.log4j.message.Message)1 StructuredDataId (org.apache.logging.log4j.message.StructuredDataId)1 StructuredDataMessage (org.apache.logging.log4j.message.StructuredDataMessage)1