I'm trying to limit the log message size, I succeed to do it with the error traceback (using ShortenedThrowableConverter) but I didn't manage to find a solution to the message itself.
I know one way is to use <pattern/> but since I'm implementing the encoder by myself.
I tried using layout but encountered with this error below:
no applicable action for [layout], current ElementPath  is [[configuration][appender][encoder][layout]]
Here is some of my code:
logback.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <appender name="console-json" class="ch.qos.logback.core.ConsoleAppender">
        <encoder class="com.test.log.logback.JsonEncoder">
            <throwableConverter class="net.logstash.logback.stacktrace.ShortenedThrowableConverter">
                <maxLength>20</maxLength>
            </throwableConverter>
        </encoder>
    </appender>
    <root level="info">
        <appender-ref ref="console-json" />
    </root>
    <shutdownHook class="ch.qos.logback.core.hook.DelayingShutdownHook"/>
    <contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator">
        <resetJUL>true</resetJUL>
    </contextListener>
</configuration>
encoder:
package com.test.log.logback;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import net.logstash.logback.stacktrace.ShortenedThrowableConverter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
public class JsonEncoder extends net.logstash.logback.encoder.LogstashEncoder {
    private String customFields;
    ShortenedThrowableConverter converter = new ShortenedThrowableConverter();
    public JsonEncoder() {
        converter.setMaxLength(10);
        setThrowableConverter(converter);
        setFieldNames(new FieldNames());
        setTimeZone("UTC");
        setFindAndRegisterJacksonModules(false);
    }   
    
}
				
                        
To limit the
messagefield within the JSON output when using thenet.logstash.logback.encoder.LogstashEncoder, you'll need to:messagefield outputmessagefield using the pattern providerFor example:
or as a custom encoder:
Alternatively, you can use
net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder(which is the superclass ofLogstashEncoder), and build up the JSON event exactly as you like with JSON providers. See here.For example:
or as a custom encoder: