[ https://issues.apache.org/jira/browse/LOG4J2-2256?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Hugo Veillette updated LOG4J2-2256: ----------------------------------- Priority: Major (was: Critical) > 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: Major > > 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. > Note that StringBuilderFormattable can only be truncated to a value greater > than or equal to 1024 bytes. So we cannot rely on this (maybe it should be > treated as a separate defect) > The outcome leads to large amount of data stored in the short message field > which impacts performance, storage and indexing. > Proposed enhancement: > Short message: Provide ability to use a pattern layout (which will inherit > the ability to set length) and/or add the ability to set arbitrary size > through the gelf layout attribute > Full message: Should contain the plain message with the stack trace (the > stack trace part was already covered properly) > 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)