当前位置: 首页>>代码示例>>Java>>正文


Java PatternParser.parse方法代码示例

本文整理汇总了Java中org.apache.logging.log4j.core.pattern.PatternParser.parse方法的典型用法代码示例。如果您正苦于以下问题:Java PatternParser.parse方法的具体用法?Java PatternParser.parse怎么用?Java PatternParser.parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.logging.log4j.core.pattern.PatternParser的用法示例。


在下文中一共展示了PatternParser.parse方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: newInstance

import org.apache.logging.log4j.core.pattern.PatternParser; //导入方法依赖的package包/类
/**
 * 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);
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:23,代码来源:ColorConverter.java

示例2: PatternProcessor

import org.apache.logging.log4j.core.pattern.PatternParser; //导入方法依赖的package包/类
/**
 * Constructor.
 * @param pattern The file pattern.
 */
public PatternProcessor(final String pattern) {
    final PatternParser parser = createPatternParser();
    final List<PatternConverter> converters = new ArrayList<PatternConverter>();
    final List<FormattingInfo> fields = new ArrayList<FormattingInfo>();
    parser.parse(pattern, converters, fields);
    final FormattingInfo[] infoArray = new FormattingInfo[fields.size()];
    patternFields = fields.toArray(infoArray);
    final ArrayPatternConverter[] converterArray = new ArrayPatternConverter[converters.size()];
    patternConverters = converters.toArray(converterArray);

    for (final ArrayPatternConverter converter : patternConverters) {
        if (converter instanceof DatePatternConverter) {
            final DatePatternConverter dateConverter = (DatePatternConverter) converter;
            frequency = calculateFrequency(dateConverter.getPattern());
        }
    }
}
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:22,代码来源:PatternProcessor.java

示例3: createFieldFormatters

import org.apache.logging.log4j.core.pattern.PatternParser; //导入方法依赖的package包/类
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;
}
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:25,代码来源:RFC5424Layout.java

示例4: PatternProcessor

import org.apache.logging.log4j.core.pattern.PatternParser; //导入方法依赖的package包/类
/**
 * Constructor.
 * @param pattern The file pattern.
 */
public PatternProcessor(final String pattern) {
    this.pattern = pattern;
    final PatternParser parser = createPatternParser();
    final List<PatternConverter> converters = new ArrayList<>();
    final List<FormattingInfo> fields = new ArrayList<>();
    parser.parse(pattern, converters, fields, false, false, false);
    final FormattingInfo[] infoArray = new FormattingInfo[fields.size()];
    patternFields = fields.toArray(infoArray);
    final ArrayPatternConverter[] converterArray = new ArrayPatternConverter[converters.size()];
    patternConverters = converters.toArray(converterArray);

    for (final ArrayPatternConverter converter : patternConverters) {
        if (converter instanceof DatePatternConverter) {
            final DatePatternConverter dateConverter = (DatePatternConverter) converter;
            frequency = calculateFrequency(dateConverter.getPattern());
        }
    }
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:23,代码来源:PatternProcessor.java

示例5: build

import org.apache.logging.log4j.core.pattern.PatternParser; //导入方法依赖的package包/类
@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);
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:19,代码来源:PatternLayout.java

示例6: createFieldFormatters

import org.apache.logging.log4j.core.pattern.PatternParser; //导入方法依赖的package包/类
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;
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:24,代码来源:Rfc5424Layout.java

示例7: newInstance

import org.apache.logging.log4j.core.pattern.PatternParser; //导入方法依赖的package包/类
/**
 * 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);
}
 
开发者ID:ggrandes,项目名称:log4j2-simplejson,代码行数:21,代码来源:SimpleJSONPatternConverter.java

示例8: PatternLayout

import org.apache.logging.log4j.core.pattern.PatternParser; //导入方法依赖的package包/类
/**
 * Constructs a EnhancedPatternLayout using the supplied conversion pattern.
 *
 * @param config The Configuration.
 * @param replace The regular expression to match.
 * @param pattern conversion pattern.
 * @param charset The character set.
 * @param alwaysWriteExceptions Whether or not exceptions should always be handled in this pattern (if {@code true},
 *                         exceptions will be written even if the pattern does not specify so).
 */
private PatternLayout(final Configuration config, final RegexReplacement replace, final String pattern,
                      final Charset charset, final boolean alwaysWriteExceptions) {
    super(charset);
    this.replace = replace;
    this.conversionPattern = pattern;
    this.config = config;
    this.alwaysWriteExceptions = alwaysWriteExceptions;
    final PatternParser parser = createPatternParser(config);
    formatters = parser.parse(pattern == null ? DEFAULT_CONVERSION_PATTERN : pattern, this.alwaysWriteExceptions);
}
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:21,代码来源:PatternLayout.java

示例9: setConversionPattern

import org.apache.logging.log4j.core.pattern.PatternParser; //导入方法依赖的package包/类
/**
 * Set the <b>ConversionPattern</b> option. This is the string which
 * controls formatting and consists of a mix of literal content and
 * conversion specifiers.
 *
 * @param conversionPattern conversion pattern.
 */
public void setConversionPattern(final String conversionPattern) {
    final String pattern = OptionConverter.convertSpecialChars(conversionPattern);
    if (pattern == null) {
        return;
    }
    final PatternParser parser = createPatternParser(this.config);
    formatters = parser.parse(pattern, this.alwaysWriteExceptions);
}
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:16,代码来源:PatternLayout.java

示例10: createFormatters

import org.apache.logging.log4j.core.pattern.PatternParser; //导入方法依赖的package包/类
/**
 */
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()]);
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:9,代码来源:ThreadLocalVsPoolBenchmark.java

示例11: getGroupCount

import org.apache.logging.log4j.core.pattern.PatternParser; //导入方法依赖的package包/类
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;
	}
 
开发者ID:pegasystems,项目名称:pega-logviewer,代码行数:16,代码来源:LogPattern.java


注:本文中的org.apache.logging.log4j.core.pattern.PatternParser.parse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。