Hugo Veillette created LOG4J2-2256:

             Summary: GelfLayout does not allow to truncate short message to 
arbitrary length
                 Key: LOG4J2-2256
             Project: Log4j 2
          Issue Type: Bug
          Components: Layouts
    Affects Versions: 2.10.0
            Reporter: Hugo Veillette


using the GelfLayout provided in Log4j2 core, we are unable to truncate the 
value of the "short_message" field to an arbitrary size for message type other 
than StringBuilderFormattable. 

The outcome leads to duplicate large amount of data through the appenders which 
ends up hurting performance, storage and network.

Proposed enhancement would be to add an attribute in the short message to set 
arbitrary length for the short message. 

Here is the  detail of 2.10.0 implementation. 

        final Message message = event.getMessage();
        if (message instanceof CharSequence) {
            JsonUtils.quoteAsString(((CharSequence)message), builder);
        } else if (gcFree && message instanceof StringBuilderFormattable) {
            final StringBuilder messageBuffer = getMessageStringBuilder();
            try {
                ((StringBuilderFormattable) message).formatTo(messageBuffer);
                JsonUtils.quoteAsString(messageBuffer, builder);
            } finally {
        } else {

    protected static final int MAX_STRING_BUILDER_SIZE = 
            size("log4j.layoutStringBuilder.maxSize", 2 * 1024));
    protected static void trimToMaxSize(final StringBuilder stringBuilder) {
        StringBuilders.trimToMaxSize(stringBuilder, MAX_STRING_BUILDER_SIZE);

This message was sent by Atlassian JIRA

Reply via email to