use of org.apache.logging.log4j.core.pattern.PatternParser in project logging-log4j2 by apache.
the class StringBuilderPool method createFormatters.
/**
*/
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()]);
}
use of org.apache.logging.log4j.core.pattern.PatternParser in project logging-log4j2 by apache.
the class PatternLayout method createPatternParser.
/**
* Creates a PatternParser.
* @param config The Configuration.
* @return The PatternParser.
*/
public static PatternParser createPatternParser(final Configuration config) {
if (config == null) {
return new PatternParser(config, KEY, LogEventPatternConverter.class);
}
PatternParser parser = config.getComponent(KEY);
if (parser == null) {
parser = new PatternParser(config, KEY, LogEventPatternConverter.class);
config.addComponent(KEY, parser);
parser = config.getComponent(KEY);
}
return parser;
}
use of org.apache.logging.log4j.core.pattern.PatternParser in project logging-log4j2 by apache.
the class Rfc5424Layout method createFieldFormatters.
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;
}
use of org.apache.logging.log4j.core.pattern.PatternParser in project logging-log4j2 by apache.
the class Rfc5424Layout method createPatternParser.
/**
* Create a PatternParser.
*
* @param config The Configuration.
* @param filterClass Filter the returned plugins after calling the plugin manager.
* @return The PatternParser.
*/
private static PatternParser createPatternParser(final Configuration config, final Class<? extends PatternConverter> filterClass) {
if (config == null) {
return new PatternParser(config, PatternLayout.KEY, LogEventPatternConverter.class, filterClass);
}
PatternParser parser = config.getComponent(COMPONENT_KEY);
if (parser == null) {
parser = new PatternParser(config, PatternLayout.KEY, ThrowablePatternConverter.class);
config.addComponent(COMPONENT_KEY, parser);
parser = config.getComponent(COMPONENT_KEY);
}
return parser;
}
use of org.apache.logging.log4j.core.pattern.PatternParser 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);
}
Aggregations