Search in sources :

Example 1 with AnsiElement

use of org.springframework.boot.ansi.AnsiElement in project spring-boot by spring-projects.

the class ColorConverter method format.

@Override
public void format(LogEvent event, StringBuilder toAppendTo) {
    StringBuilder buf = new StringBuilder();
    for (PatternFormatter formatter : this.formatters) {
        formatter.format(event, buf);
    }
    if (buf.length() > 0) {
        AnsiElement element = this.styling;
        if (element == null) {
            // Assume highlighting
            element = LEVELS.get(event.getLevel().intLevel());
            element = (element == null ? AnsiColor.GREEN : element);
        }
        appendAnsiString(toAppendTo, buf.toString(), element);
    }
}
Also used : PatternFormatter(org.apache.logging.log4j.core.pattern.PatternFormatter) AnsiElement(org.springframework.boot.ansi.AnsiElement)

Example 2 with AnsiElement

use of org.springframework.boot.ansi.AnsiElement 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)

Example 3 with AnsiElement

use of org.springframework.boot.ansi.AnsiElement in project spring-boot by spring-projects.

the class ColorConverter method transform.

@Override
protected String transform(ILoggingEvent event, String in) {
    AnsiElement element = ELEMENTS.get(getFirstOption());
    if (element == null) {
        // Assume highlighting
        element = LEVELS.get(event.getLevel().toInteger());
        element = (element == null ? AnsiColor.GREEN : element);
    }
    return toAnsiString(in, element);
}
Also used : AnsiElement(org.springframework.boot.ansi.AnsiElement)

Example 4 with AnsiElement

use of org.springframework.boot.ansi.AnsiElement in project spring-boot by spring-projects.

the class ImageBanner method printBanner.

private void printBanner(BufferedImage image, int margin, boolean invert, PrintStream out) {
    AnsiElement background = (invert ? AnsiBackground.BLACK : AnsiBackground.DEFAULT);
    out.print(AnsiOutput.encode(AnsiColor.DEFAULT));
    out.print(AnsiOutput.encode(background));
    out.println();
    out.println();
    AnsiColor lastColor = AnsiColor.DEFAULT;
    for (int y = 0; y < image.getHeight(); y++) {
        for (int i = 0; i < margin; i++) {
            out.print(" ");
        }
        for (int x = 0; x < image.getWidth(); x++) {
            Color color = new Color(image.getRGB(x, y), false);
            AnsiColor ansiColor = AnsiColors.getClosest(color);
            if (ansiColor != lastColor) {
                out.print(AnsiOutput.encode(ansiColor));
                lastColor = ansiColor;
            }
            out.print(getAsciiPixel(color, invert));
        }
        out.println();
    }
    out.print(AnsiOutput.encode(AnsiColor.DEFAULT));
    out.print(AnsiOutput.encode(AnsiBackground.DEFAULT));
    out.println();
}
Also used : Color(java.awt.Color) AnsiColor(org.springframework.boot.ansi.AnsiColor) AnsiElement(org.springframework.boot.ansi.AnsiElement) AnsiColor(org.springframework.boot.ansi.AnsiColor)

Aggregations

AnsiElement (org.springframework.boot.ansi.AnsiElement)4 PatternFormatter (org.apache.logging.log4j.core.pattern.PatternFormatter)2 Color (java.awt.Color)1 PatternParser (org.apache.logging.log4j.core.pattern.PatternParser)1 AnsiColor (org.springframework.boot.ansi.AnsiColor)1