All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jboss.logmanager.formatters.PatternFormatter Maven / Gradle / Ivy

There is a newer version: 1.2.0.Final
Show newest version
/*
 * Copyright 2018 Red Hat, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jboss.logmanager.formatters;

/**
 * A formatter which uses a text pattern to format messages.
 */
public class PatternFormatter extends MultistepFormatter {

    private volatile String pattern;

    private volatile ColorMap colors;
    /**
     * Construct a new instance.
     */
    public PatternFormatter() {
        this.colors = ColorMap.DEFAULT_COLOR_MAP;
    }

    /**
     * Construct a new instance.
     *
     * @param pattern the initial pattern
     */
    public PatternFormatter(String pattern) {
        super(FormatStringParser.getSteps(pattern, ColorMap.DEFAULT_COLOR_MAP));
        this.colors = ColorMap.DEFAULT_COLOR_MAP;
        this.pattern = pattern;
    }

    /**
     * Construct a new instance.
     *
     * @param pattern the initial pattern
     * @param colors the color map to use
     */
    public PatternFormatter(String pattern, String colors) {
        ColorMap colorMap = ColorMap.create(colors);
        this.colors = colorMap;
        this.pattern = pattern;
        setSteps(FormatStringParser.getSteps(pattern, colorMap));
    }

    /**
     * Get the current format pattern.
     *
     * @return the pattern
     */
    public String getPattern() {
        return pattern;
    }

    /**
     * Set the format pattern.
     *
     * @param pattern the pattern
     */
    public void setPattern(final String pattern) {
        if (pattern == null) {
            setSteps(null);
        } else {
            setSteps(FormatStringParser.getSteps(pattern, colors));
        }
        this.pattern = pattern;
    }

    /**
     * Set the color map to use for log levels when %K{level} is used.
     *
     * 

The format is level:color,level:color,... * *

Where level is either a numerical value or one of the following constants:

* * * * * * * * * * * * * * *
fatal
error
severe
warn
warning
info
config
debug
trace
fine
finer
finest
* *

Color is one of the following constants:

* * * * * * * * * * * * * * * * * * * *
clear
black
red
green
yellow
blue
magenta
cyan
white
brightblack
brightred
brightgreen
brightyellow
brightblue
brightmagenta
brightcyan
brightwhite
* * @param colors a colormap expression string described above */ public void setColors(String colors) { ColorMap colorMap = ColorMap.create(colors); this.colors = colorMap; if (pattern != null) { setSteps(FormatStringParser.getSteps(pattern, colorMap)); } } public String getColors() { return this.colors.toString(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy