Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider log4j2.formatMsgNoLookups for additionalFields #157

Merged
merged 1 commit into from
Dec 17, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.apache.logging.log4j.message.Message;
import org.apache.logging.log4j.message.MultiformatMessage;
import org.apache.logging.log4j.message.ObjectMessage;
import org.apache.logging.log4j.util.PropertiesUtil;
import org.apache.logging.log4j.util.StringBuilderFormattable;

import java.nio.charset.Charset;
Expand All @@ -63,6 +64,8 @@ public class EcsLayout extends AbstractStringLayout {
private static final ObjectMessageJacksonSerializer JACKSON_SERIALIZER = ObjectMessageJacksonSerializer.Resolver.resolve();
private static final MdcSerializer MDC_SERIALIZER = MdcSerializer.Resolver.resolve();
private static final MultiFormatHandler MULTI_FORMAT_HANDLER = MultiFormatHandler.Resolver.resolve();
private static final boolean FORMAT_MESSAGES_PATTERN_DISABLE_LOOKUPS = PropertiesUtil.getProperties().getBooleanProperty(
"log4j2.formatMsgNoLookups", false);

private final KeyValuePair[] additionalFields;
private final PatternFormatter[][] fieldValuePatternFormatter;
Expand Down Expand Up @@ -156,7 +159,7 @@ private void serializeAdditionalFieldsAndMDC(LogEvent event, StringBuilder build
if (buffer.length() > 0) {
value = buffer;
}
} else if (valueNeedsLookup(additionalField.getValue())) {
} else if (valueNeedsLookup(additionalField.getValue()) && !FORMAT_MESSAGES_PATTERN_DISABLE_LOOKUPS) {
StringBuilder lookupValue = EcsJsonSerializer.getMessageStringBuilder();
lookupValue.append(additionalField.getValue());
if (strSubstitutor.replaceIn(event, lookupValue)) {
Expand Down