use of org.apache.logging.log4j.core.pattern.PatternFormatter 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);
}
}
use of org.apache.logging.log4j.core.pattern.PatternFormatter 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.PatternFormatter in project logging-log4j2 by apache.
the class Rfc5424Layout method appendMessage.
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.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);
}
}
use of org.apache.logging.log4j.core.pattern.PatternFormatter 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.PatternFormatter in project logging-log4j2 by apache.
the class ScriptPatternSelector method getFormatters.
@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;
}
Aggregations