[ https://issues.apache.org/jira/browse/LOG4J2-2256?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16369575#comment-16369575 ]
Remko Popma commented on LOG4J2-2256: ------------------------------------- Will you be able to provide a patch or pull request, ideally with unit tests? > GelfLayout does not allow to truncate short message to arbitrary length > ----------------------------------------------------------------------- > > Key: LOG4J2-2256 > URL: https://issues.apache.org/jira/browse/LOG4J2-2256 > Project: Log4j 2 > Issue Type: Bug > Components: Layouts > Affects Versions: 2.10.0 > Reporter: Hugo Veillette > Priority: Critical > > Hi, > 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 large amount of data duplicated through the appenders > which ends up hurting performance, storage and network. > Proposed enhancement would be to add an attribute in the layout definition to > set arbitrary length for the short message. > Here is the detail of 2.10.0 implementation. > {code:java|title="org.apache.logging.log4j.core.layout.GelfLayout"} > builder.append("\"short_message\":\""); > 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 { > trimToMaxSize(messageBuffer); > } > } else { > > JsonUtils.quoteAsString(toNullSafeString(message.getFormattedMessage()), > builder); > } > {code} > {code:java|title="org.apache.logging.log4j.core.layout.AbstractStringLayout"} > protected static final int MAX_STRING_BUILDER_SIZE = > Math.max(DEFAULT_STRING_BUILDER_SIZE, > size("log4j.layoutStringBuilder.maxSize", 2 * 1024)); > protected static void trimToMaxSize(final StringBuilder stringBuilder) { > StringBuilders.trimToMaxSize(stringBuilder, MAX_STRING_BUILDER_SIZE); > } > {code} -- This message was sent by Atlassian JIRA (v7.6.3#76005)