You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "Hugo Veillette (JIRA)" <ji...@apache.org> on 2018/02/20 13:40:00 UTC
[jira] [Comment Edited] (LOG4J2-2256) GelfLayout does not allow to
truncate short message to arbitrary length
[ https://issues.apache.org/jira/browse/LOG4J2-2256?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16369576#comment-16369576 ]
Hugo Veillette edited comment on LOG4J2-2256 at 2/20/18 1:39 PM:
-----------------------------------------------------------------
Hi, that's the plan, we should be able to provide it. [~ideruga] is on the case.
was (Author: hugo.veillette@iaah.ca):
Hi, that's the plan, we should be able to provide it tomorrow. [~ideruga] is on the case.
> 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.
> 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)