4848import org .apache .logging .log4j .message .Message ;
4949import org .apache .logging .log4j .message .MultiformatMessage ;
5050import org .apache .logging .log4j .message .ObjectMessage ;
51+ import org .apache .logging .log4j .util .PropertiesUtil ;
5152import org .apache .logging .log4j .util .StringBuilderFormattable ;
5253
5354import java .nio .charset .Charset ;
@@ -63,6 +64,8 @@ public class EcsLayout extends AbstractStringLayout {
6364 private static final ObjectMessageJacksonSerializer JACKSON_SERIALIZER = ObjectMessageJacksonSerializer .Resolver .resolve ();
6465 private static final MdcSerializer MDC_SERIALIZER = MdcSerializer .Resolver .resolve ();
6566 private static final MultiFormatHandler MULTI_FORMAT_HANDLER = MultiFormatHandler .Resolver .resolve ();
67+ private static final boolean FORMAT_MESSAGES_PATTERN_DISABLE_LOOKUPS = PropertiesUtil .getProperties ().getBooleanProperty (
68+ "log4j2.formatMsgNoLookups" , false );
6669
6770 private final KeyValuePair [] additionalFields ;
6871 private final PatternFormatter [][] fieldValuePatternFormatter ;
@@ -156,7 +159,7 @@ private void serializeAdditionalFieldsAndMDC(LogEvent event, StringBuilder build
156159 if (buffer .length () > 0 ) {
157160 value = buffer ;
158161 }
159- } else if (valueNeedsLookup (additionalField .getValue ())) {
162+ } else if (valueNeedsLookup (additionalField .getValue ()) && ! FORMAT_MESSAGES_PATTERN_DISABLE_LOOKUPS ) {
160163 StringBuilder lookupValue = EcsJsonSerializer .getMessageStringBuilder ();
161164 lookupValue .append (additionalField .getValue ());
162165 if (strSubstitutor .replaceIn (event , lookupValue )) {
0 commit comments