"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractJacksonLayout.java" between
apache-log4j-2.11.1-src.tar.gz and apache-log4j-2.11.2-src.tar.gz

About: Apache Log4j 2 is a logging library for Java. Source distribution (Java).

AbstractJacksonLayout.java  (apache-log4j-2.11.1-src):AbstractJacksonLayout.java  (apache-log4j-2.11.2-src)
skipping to change at line 180 skipping to change at line 180
public B setIncludeNullDelimiter(final boolean includeNullDelimiter) { public B setIncludeNullDelimiter(final boolean includeNullDelimiter) {
this.includeNullDelimiter = includeNullDelimiter; this.includeNullDelimiter = includeNullDelimiter;
return asBuilder(); return asBuilder();
} }
/** /**
* Additional fields to set on each log event. * Additional fields to set on each log event.
* *
* @return this builder * @return this builder
*/ */
public B setAdditionalFields(KeyValuePair[] additionalFields) { public B setAdditionalFields(final KeyValuePair[] additionalFields) {
this.additionalFields = additionalFields; this.additionalFields = additionalFields;
return asBuilder(); return asBuilder();
} }
} }
protected final String eol; protected final String eol;
protected final ObjectWriter objectWriter; protected final ObjectWriter objectWriter;
protected final boolean compact; protected final boolean compact;
protected final boolean complete; protected final boolean complete;
protected final boolean includeNullDelimiter; protected final boolean includeNullDelimiter;
skipping to change at line 234 skipping to change at line 234
private static ResolvableKeyValuePair[] prepareAdditionalFields(final Config uration config, final KeyValuePair[] additionalFields) { private static ResolvableKeyValuePair[] prepareAdditionalFields(final Config uration config, final KeyValuePair[] additionalFields) {
if (additionalFields == null || additionalFields.length == 0) { if (additionalFields == null || additionalFields.length == 0) {
// No fields set // No fields set
return new ResolvableKeyValuePair[0]; return new ResolvableKeyValuePair[0];
} }
// Convert to specific class which already determines whether values nee ds lookup during serialization // Convert to specific class which already determines whether values nee ds lookup during serialization
final ResolvableKeyValuePair[] resolvableFields = new ResolvableKeyValue Pair[additionalFields.length]; final ResolvableKeyValuePair[] resolvableFields = new ResolvableKeyValue Pair[additionalFields.length];
for (int i = 0; i < additionalFields.length; i++) { for (int i = 0; i < additionalFields.length; i++) {
ResolvableKeyValuePair resolvable = resolvableFields[i] = new Resolv ableKeyValuePair(additionalFields[i]); final ResolvableKeyValuePair resolvable = resolvableFields[i] = new ResolvableKeyValuePair(additionalFields[i]);
// Validate // Validate
if (config == null && resolvable.valueNeedsLookup) { if (config == null && resolvable.valueNeedsLookup) {
throw new IllegalArgumentException("configuration needs to be se t when there are additional fields with variables"); throw new IllegalArgumentException("configuration needs to be se t when there are additional fields with variables");
} }
} }
return resolvableFields; return resolvableFields;
} }
skipping to change at line 274 skipping to change at line 274
private static LogEvent convertMutableToLog4jEvent(final LogEvent event) { private static LogEvent convertMutableToLog4jEvent(final LogEvent event) {
// TODO Jackson-based layouts have certain filters set up for Log4jLogEv ent. // TODO Jackson-based layouts have certain filters set up for Log4jLogEv ent.
// TODO Need to set up the same filters for MutableLogEvent but don't kn ow how... // TODO Need to set up the same filters for MutableLogEvent but don't kn ow how...
// This is a workaround. // This is a workaround.
return event instanceof Log4jLogEvent ? event : Log4jLogEvent.createMeme nto(event); return event instanceof Log4jLogEvent ? event : Log4jLogEvent.createMeme nto(event);
} }
protected Object wrapLogEvent(final LogEvent event) { protected Object wrapLogEvent(final LogEvent event) {
if (additionalFields.length > 0) { if (additionalFields.length > 0) {
// Construct map for serialization - note that we are intentionally using original LogEvent // Construct map for serialization - note that we are intentionally using original LogEvent
Map<String, String> additionalFieldsMap = resolveAdditionalFields(ev ent); final Map<String, String> additionalFieldsMap = resolveAdditionalFie lds(event);
// This class combines LogEvent with AdditionalFields during seriali zation // This class combines LogEvent with AdditionalFields during seriali zation
return new LogEventWithAdditionalFields(event, additionalFieldsMap); return new LogEventWithAdditionalFields(event, additionalFieldsMap);
} else { } else {
// No additional fields, return original object // No additional fields, return original object
return event; return event;
} }
} }
private Map<String, String> resolveAdditionalFields(LogEvent logEvent) { private Map<String, String> resolveAdditionalFields(final LogEvent logEvent) {
// Note: LinkedHashMap retains order // Note: LinkedHashMap retains order
final Map<String, String> additionalFieldsMap = new LinkedHashMap<>(addi tionalFields.length); final Map<String, String> additionalFieldsMap = new LinkedHashMap<>(addi tionalFields.length);
final StrSubstitutor strSubstitutor = configuration.getStrSubstitutor(); final StrSubstitutor strSubstitutor = configuration.getStrSubstitutor();
// Go over each field // Go over each field
for (ResolvableKeyValuePair pair : additionalFields) { for (final ResolvableKeyValuePair pair : additionalFields) {
if (pair.valueNeedsLookup) { if (pair.valueNeedsLookup) {
// Resolve value // Resolve value
additionalFieldsMap.put(pair.key, strSubstitutor.replace(logEven t, pair.value)); additionalFieldsMap.put(pair.key, strSubstitutor.replace(logEven t, pair.value));
} else { } else {
// Plain text value // Plain text value
additionalFieldsMap.put(pair.key, pair.value); additionalFieldsMap.put(pair.key, pair.value);
} }
} }
return additionalFieldsMap; return additionalFieldsMap;
skipping to change at line 319 skipping to change at line 319
markEvent(); markEvent();
} }
@JsonRootName(XmlConstants.ELT_EVENT) @JsonRootName(XmlConstants.ELT_EVENT)
@JacksonXmlRootElement(namespace = XmlConstants.XML_NAMESPACE, localName = X mlConstants.ELT_EVENT) @JacksonXmlRootElement(namespace = XmlConstants.XML_NAMESPACE, localName = X mlConstants.ELT_EVENT)
public static class LogEventWithAdditionalFields { public static class LogEventWithAdditionalFields {
private final Object logEvent; private final Object logEvent;
private final Map<String, String> additionalFields; private final Map<String, String> additionalFields;
public LogEventWithAdditionalFields(Object logEvent, Map<String, String> additionalFields) { public LogEventWithAdditionalFields(final Object logEvent, final Map<Str ing, String> additionalFields) {
this.logEvent = logEvent; this.logEvent = logEvent;
this.additionalFields = additionalFields; this.additionalFields = additionalFields;
} }
@JsonUnwrapped @JsonUnwrapped
public Object getLogEvent() { public Object getLogEvent() {
return logEvent; return logEvent;
} }
@JsonAnyGetter @JsonAnyGetter
skipping to change at line 342 skipping to change at line 342
return additionalFields; return additionalFields;
} }
} }
protected static class ResolvableKeyValuePair { protected static class ResolvableKeyValuePair {
final String key; final String key;
final String value; final String value;
final boolean valueNeedsLookup; final boolean valueNeedsLookup;
ResolvableKeyValuePair(KeyValuePair pair) { ResolvableKeyValuePair(final KeyValuePair pair) {
this.key = pair.getKey(); this.key = pair.getKey();
this.value = pair.getValue(); this.value = pair.getValue();
this.valueNeedsLookup = AbstractJacksonLayout.valueNeedsLookup(this. value); this.valueNeedsLookup = AbstractJacksonLayout.valueNeedsLookup(this. value);
} }
} }
} }
 End of changes. 7 change blocks. 
7 lines changed or deleted 7 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)