Java 类org.apache.logging.log4j.core.pattern.PatternFormatter 实例源码

项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:ColorConverter.java   
/**
 * 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);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:ColorConverter.java   
@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);
    }
}
项目:spring-boot-concourse    文件:ColorConverter.java   
/**
 * 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);
}
项目:spring-boot-concourse    文件:ColorConverter.java   
@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);
    }
}
项目:contestparser    文件:ColorConverter.java   
/**
 * 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);
}
项目:contestparser    文件:ColorConverter.java   
@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);
    }
}
项目:log4j2    文件:RFC5424Layout.java   
private Map<String, FieldFormatter> createFieldFormatters(final LoggerFields[] loggerFields,
        final Configuration config) {
    final Map<String, FieldFormatter> sdIdMap = new HashMap<String, FieldFormatter>();

    if (loggerFields != null) {
        for (final LoggerFields lField : loggerFields) {
            final StructuredDataId key = lField.getSdId() == null ? mdcSDID : lField.getSdId();
            final Map<String, List<PatternFormatter>> sdParams = new HashMap<String, List<PatternFormatter>>();
            final Map<String, String> fields = lField.getMap();
            if (!fields.isEmpty()) {
                final PatternParser fieldParser = createPatternParser(config, null);

                for (final Map.Entry<String, String> entry : fields.entrySet()) {
                    final List<PatternFormatter> formatters = fieldParser.parse(entry.getValue(), false);
                    sdParams.put(entry.getKey(), formatters);
                }
                final FieldFormatter fieldFormatter = new FieldFormatter(sdParams,
                        lField.getDiscardIfAllFieldsAreEmpty());
                sdIdMap.put(key.toString(), fieldFormatter);
            }
        }
    }
    return sdIdMap.size() > 0 ? sdIdMap : null;
}
项目:log4j2    文件:RFC5424Layout.java   
private void appendMessage(final StringBuilder buffer, final LogEvent event) {
    final Message message = event.getMessage();
    final String text = message.getFormat();

    if (text != null && text.length() > 0) {
        buffer.append(" ").append(escapeNewlines(text, escapeNewLine));
    }

    if (exceptionFormatters != null && event.getThrown() != null) {
        final StringBuilder exception = new StringBuilder(LF);
        for (final PatternFormatter formatter : exceptionFormatters) {
            formatter.format(event, exception);
        }
        buffer.append(escapeNewlines(exception.toString(), escapeNewLine));
    }
    if (includeNewLine) {
        buffer.append(LF);
    }
}
项目:logging-log4j2    文件:PatternLayout.java   
@Override
public Serializer build() {
    if (Strings.isEmpty(pattern) && Strings.isEmpty(defaultPattern)) {
        return null;
    }
    if (patternSelector == null) {
        try {
            final PatternParser parser = createPatternParser(configuration);
            final List<PatternFormatter> list = parser.parse(pattern == null ? defaultPattern : pattern,
                    alwaysWriteExceptions, disableAnsi, noConsoleNoAnsi);
            final PatternFormatter[] formatters = list.toArray(new PatternFormatter[0]);
            return new PatternSerializer(formatters, replace);
        } catch (final RuntimeException ex) {
            throw new IllegalArgumentException("Cannot parse pattern '" + pattern + "'", ex);
        }
    }
    return new PatternSelectorSerializer(patternSelector, replace);
}
项目:logging-log4j2    文件:Rfc5424Layout.java   
private Map<String, FieldFormatter> createFieldFormatters(final LoggerFields[] loggerFields,
        final Configuration config) {
    final Map<String, FieldFormatter> sdIdMap = new HashMap<>(loggerFields == null ? 0 : loggerFields.length);
    if (loggerFields != null) {
        for (final LoggerFields loggerField : loggerFields) {
            final StructuredDataId key = loggerField.getSdId() == null ? mdcSdId : loggerField.getSdId();
            final Map<String, List<PatternFormatter>> sdParams = new HashMap<>();
            final Map<String, String> fields = loggerField.getMap();
            if (!fields.isEmpty()) {
                final PatternParser fieldParser = createPatternParser(config, null);

                for (final Map.Entry<String, String> entry : fields.entrySet()) {
                    final List<PatternFormatter> formatters = fieldParser.parse(entry.getValue());
                    sdParams.put(entry.getKey(), formatters);
                }
                final FieldFormatter fieldFormatter = new FieldFormatter(sdParams,
                        loggerField.getDiscardIfAllFieldsAreEmpty());
                sdIdMap.put(key.toString(), fieldFormatter);
            }
        }
    }
    return sdIdMap.size() > 0 ? sdIdMap : null;
}
项目:logging-log4j2    文件:Rfc5424Layout.java   
private void appendMessage(final StringBuilder buffer, final LogEvent event) {
    final Message message = event.getMessage();
    // This layout formats StructuredDataMessages instead of delegating to the Message itself.
    final String text = (message instanceof StructuredDataMessage || message instanceof MessageCollectionMessage)
            ? message.getFormat() : message.getFormattedMessage();

    if (text != null && text.length() > 0) {
        buffer.append(' ').append(escapeNewlines(text, escapeNewLine));
    }

    if (exceptionFormatters != null && event.getThrown() != null) {
        final StringBuilder exception = new StringBuilder(LF);
        for (final PatternFormatter formatter : exceptionFormatters) {
            formatter.format(event, exception);
        }
        buffer.append(escapeNewlines(exception.toString(), escapeNewLine));
    }
    if (includeNewLine) {
        buffer.append(LF);
    }
}
项目:cf-java-logging-support    文件:JsonPatternLayout.java   
@Override
public String toSerializable(LogEvent event) {
    PatternSelector selector = getSelector(event);
    final StringBuilder buf = getStringBuilder();
    PatternFormatter[] formatters = selector.getFormatters(event);
    final int len = formatters.length;
    for (int i = 0; i < len; i++) {
        formatters[i].format(event, buf);
    }
    String str = buf.toString();
    return str;
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:ColorConverter.java   
@Override
public boolean handlesThrowable() {
    for (PatternFormatter formatter : this.formatters) {
        if (formatter.handlesThrowable()) {
            return true;
        }
    }
    return super.handlesThrowable();
}
项目:log4j2-simplejson    文件:SimpleJSONPatternConverter.java   
/**
 * Obtains an instance of pattern converter.
 * 
 * @param config The Configuration.
 * @param options options, may be null.
 * @return instance of pattern converter.
 */
public static SimpleJSONPatternConverter newInstance(final Configuration config, final String[] options) {
    if (options.length != 1) {
        LOGGER.error("Incorrect number of options on json. Expected 1, received " + options.length);
        return null;
    }
    if (options[0] == null) {
        LOGGER.error("No pattern supplied on json");
        return null;
    }
    final PatternParser parser = PatternLayout.createPatternParser(config);
    final List<PatternFormatter> formatters = parser.parse(options[0]);
    return new SimpleJSONPatternConverter(formatters);
}
项目:log4j2-simplejson    文件:SimpleJSONPatternConverter.java   
/**
 * {@inheritDoc}
 */
@Override
public void format(final LogEvent event, final StringBuilder toAppendTo) {
    final StringBuilder buf = new StringBuilder();
    for (final PatternFormatter formatter : formatters) {
        formatter.format(event, buf);
    }
    EncoderJSON.escapeJSON(buf, toAppendTo);
}
项目:spring-boot-concourse    文件:ColorConverter.java   
@Override
public boolean handlesThrowable() {
    for (PatternFormatter formatter : this.formatters) {
        if (formatter.handlesThrowable()) {
            return true;
        }
    }
    return super.handlesThrowable();
}
项目:contestparser    文件:ColorConverter.java   
@Override
public boolean handlesThrowable() {
    for (PatternFormatter formatter : this.formatters) {
        if (formatter.handlesThrowable()) {
            return true;
        }
    }
    return super.handlesThrowable();
}
项目:log4j2    文件:RFC5424Layout.java   
public StructuredDataElement format(final LogEvent event) {
    final Map<String, String> map = new HashMap<String, String>();

    for (final Map.Entry<String, List<PatternFormatter>> entry : delegateMap.entrySet()) {
        final StringBuilder buffer = new StringBuilder();
        for (final PatternFormatter formatter : entry.getValue()) {
            formatter.format(event, buffer);
        }
        map.put(entry.getKey(), buffer.toString());
    }
    return new StructuredDataElement(map, discardIfEmpty);
}
项目:log4j2    文件:PatternLayout.java   
/**
 * Formats a logging event to a writer.
 *
 *
 * @param event logging event to be formatted.
 * @return The event formatted as a String.
 */
@Override
public String toSerializable(final LogEvent event) {
    final StringBuilder buf = new StringBuilder();
    for (final PatternFormatter formatter : formatters) {
        formatter.format(event, buf);
    }
    String str = buf.toString();
    if (replace != null) {
        str = replace.format(str);
    }
    return str;
}
项目:logging-log4j2    文件:ThreadLocalVsPoolBenchmark.java   
/**
 */
private static PatternFormatter[] createFormatters() {
    final Configuration config = new DefaultConfiguration();
    final PatternParser parser = new PatternParser(config, "Converter", LogEventPatternConverter.class);
    final List<PatternFormatter> result = parser.parse(LOG4JPATTERN, false, true);
    return result.toArray(new PatternFormatter[result.size()]);
}
项目:logging-log4j2    文件:MarkerPatternSelector.java   
@Override
public PatternFormatter[] getFormatters(final LogEvent event) {
    final Marker marker = event.getMarker();
    if (marker == null) {
        return defaultFormatters;
    }
    for (final String key : formatterMap.keySet()) {
        if (marker.isInstanceOf(key)) {
            return formatterMap.get(key);
        }
    }
    return defaultFormatters;
}
项目:logging-log4j2    文件:PatternLayout.java   
@Override
public StringBuilder toSerializable(final LogEvent event, final StringBuilder buffer) {
    final PatternFormatter[] formatters = patternSelector.getFormatters(event);
    final int len = formatters.length;
    for (int i = 0; i < len; i++) {
        formatters[i].format(event, buffer);
    }
    if (replace != null) { // creates temporary objects
        String str = buffer.toString();
        str = replace.format(str);
        buffer.setLength(0);
        buffer.append(str);
    }
    return buffer;
}
项目:logging-log4j2    文件:ScriptPatternSelector.java   
@Override
public PatternFormatter[] getFormatters(final LogEvent event) {
    final SimpleBindings bindings = new SimpleBindings();
    bindings.putAll(configuration.getProperties());
    bindings.put("substitutor", configuration.getStrSubstitutor());
    bindings.put("logEvent", event);
    final Object object = configuration.getScriptManager().execute(script.getName(), bindings);
    if (object == null) {
        return defaultFormatters;
    }
    final PatternFormatter[] patternFormatter = formatterMap.get(object.toString());

    return patternFormatter == null ? defaultFormatters : patternFormatter;
}
项目:logging-log4j2    文件:Rfc5424Layout.java   
public StructuredDataElement format(final LogEvent event) {
    final Map<String, String> map = new HashMap<>(delegateMap.size());

    for (final Map.Entry<String, List<PatternFormatter>> entry : delegateMap.entrySet()) {
        final StringBuilder buffer = new StringBuilder();
        for (final PatternFormatter formatter : entry.getValue()) {
            formatter.format(event, buffer);
        }
        map.put(entry.getKey(), buffer.toString());
    }
    return new StructuredDataElement(map, eventPrefix, discardIfEmpty);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:ColorConverter.java   
private ColorConverter(List<PatternFormatter> formatters, AnsiElement styling) {
    super("style", "style");
    this.formatters = formatters;
    this.styling = styling;
}
项目:spring-boot-concourse    文件:ColorConverter.java   
private ColorConverter(List<PatternFormatter> formatters, AnsiElement styling) {
    super("style", "style");
    this.formatters = formatters;
    this.styling = styling;
}
项目:contestparser    文件:ColorConverter.java   
private ColorConverter(List<PatternFormatter> formatters, AnsiElement styling) {
    super("style", "style");
    this.formatters = formatters;
    this.styling = styling;
}
项目:log4j2    文件:RFC5424Layout.java   
public FieldFormatter(final Map<String, List<PatternFormatter>> fieldMap, final boolean discardIfEmpty) {
    this.discardIfEmpty = discardIfEmpty;
    this.delegateMap = fieldMap;
}
项目:logging-log4j2    文件:NoGcLayout.java   
PatternSerializer2() {
    this(new PatternFormatter[]{
            new PatternFormatter(NoGcMessagePatternConverter.newInstance(null, null),
                    FormattingInfo.getDefault()),
    });
}
项目:logging-log4j2    文件:NoGcLayout.java   
private PatternSerializer2(final PatternFormatter[] formatters) {
    super();
    this.formatters = formatters;
}
项目:logging-log4j2    文件:PatternLayout.java   
private PatternSerializer(final PatternFormatter[] formatters, final RegexReplacement replace) {
    super();
    this.formatters = formatters;
    this.replace = replace;
}
项目:logging-log4j2    文件:Rfc5424Layout.java   
public FieldFormatter(final Map<String, List<PatternFormatter>> fieldMap, final boolean discardIfEmpty) {
    this.discardIfEmpty = discardIfEmpty;
    this.delegateMap = fieldMap;
}
项目:pega-logviewer    文件:LogPattern.java   
public int getGroupCount() {

        int groupCount = 0;

        if ((logPatternString != null) && (!"".equals(logPatternString))) {

            PatternParser patternParser = new PatternParser("Converter");

            List<PatternFormatter> patternFormatterList = patternParser.parse(logPatternString);

            groupCount = patternFormatterList.size();
        }

        return groupCount;
    }
项目:log4j2-simplejson    文件:SimpleJSONPatternConverter.java   
/**
 * Private constructor.
 * 
 * @param formatters The PatternFormatters to generate the text to manipulate.
 */
private SimpleJSONPatternConverter(final List<PatternFormatter> formatters) {
    super("json", "json");
    this.formatters = formatters;
}
项目:logging-log4j2    文件:PatternSelector.java   
PatternFormatter[] getFormatters(LogEvent event);