You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "Carter Kozak (Jira)" <ji...@apache.org> on 2019/09/11 16:21:00 UTC

[jira] [Commented] (LOG4J2-2691) Support to limit the message length

    [ https://issues.apache.org/jira/browse/LOG4J2-2691?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16927736#comment-16927736 ] 

Carter Kozak commented on LOG4J2-2691:
--------------------------------------

Hi Samuel, unfortunately we don't have such a feature as far as I'm aware.

If the problem is that parameters have large toString values, you may be able to format messages asynchronously to limit the number of parameter string values on heap at any point in time to one. This only applies to non-reusable messages, which is why it requires the second pref to enable ParameterizedMessageFactory (non-reusable messages)
Danger: If you log a mutable object, it may be changed before the layout is executed.
For example, the following will result in 1 if {{log4j.format.msg.async}} is set, and 0 if it is not.

{code:java}
AtomicInteger value = new AtomicInteger(0);
log.info("{}", value);
value.incrementAndGet();
{code}

Config:
{code}
# https://logging.apache.org/log4j/2.x/manual/configuration.html#SystemProperties
log4j.format.msg.async = true
log4j2.messageFactory = org.apache.logging.log4j.message.ParameterizedMessageFactory
{code}


> Support to limit the message length
> -----------------------------------
>
>                 Key: LOG4J2-2691
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-2691
>             Project: Log4j 2
>          Issue Type: Improvement
>            Reporter: samuel ma
>            Priority: Major
>
> We are using log4j2 2.11.1 + disruptor, and running into a OutOfMemory Error. The reason is App log some huge message, and the consumer is very slow then disruptor RingBuffer is full.  Is that possible to limit the message length (not 'maxLen' in PatternLayout, maxLen is just the message length for layout) before RingBuffer enqueue by some configuration?



--
This message was sent by Atlassian Jira
(v8.3.2#803003)