48
48
import org .apache .logging .log4j .message .Message ;
49
49
import org .apache .logging .log4j .message .MultiformatMessage ;
50
50
import org .apache .logging .log4j .message .ObjectMessage ;
51
+ import org .apache .logging .log4j .util .PropertiesUtil ;
51
52
import org .apache .logging .log4j .util .StringBuilderFormattable ;
52
53
53
54
import java .nio .charset .Charset ;
@@ -63,6 +64,8 @@ public class EcsLayout extends AbstractStringLayout {
63
64
private static final ObjectMessageJacksonSerializer JACKSON_SERIALIZER = ObjectMessageJacksonSerializer .Resolver .resolve ();
64
65
private static final MdcSerializer MDC_SERIALIZER = MdcSerializer .Resolver .resolve ();
65
66
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 );
66
69
67
70
private final KeyValuePair [] additionalFields ;
68
71
private final PatternFormatter [][] fieldValuePatternFormatter ;
@@ -156,7 +159,7 @@ private void serializeAdditionalFieldsAndMDC(LogEvent event, StringBuilder build
156
159
if (buffer .length () > 0 ) {
157
160
value = buffer ;
158
161
}
159
- } else if (valueNeedsLookup (additionalField .getValue ())) {
162
+ } else if (valueNeedsLookup (additionalField .getValue ()) && ! FORMAT_MESSAGES_PATTERN_DISABLE_LOOKUPS ) {
160
163
StringBuilder lookupValue = EcsJsonSerializer .getMessageStringBuilder ();
161
164
lookupValue .append (additionalField .getValue ());
162
165
if (strSubstitutor .replaceIn (event , lookupValue )) {
0 commit comments