I am using logstash-logback-encoder to print logs in json format.
Below is my logback-spring.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="sample" class = "org.ssn.app.config.CustomLogService">
</appender>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="net.logstash.logback.encoder.LogstashEncoder">
<provider class="net.logstash.logback.composite.loggingevent.ArgumentsJsonProvider"/>
</encoder>
</appender>
<logger name="org.ssn.app" additivity="false" level="DEBUG">
<appender-ref ref="STDOUT"/>
</logger>
<root level="INFO">
<appender-ref ref="STDOUT"/>
</root>
</configuration>
- Below my code snippet
JSONObject lJsonObj = new JSONObject();
lJsonObj.put("dl_no","DL10252");
logger.debug(lJsonObj.toString,Markers.append("ss","sss"));
- The output is below
{
"@timestamp": "2021-06-17T18:49:07.914+05:30",
"@version": "1",
"message": "{\"dl_no\":\"DL10252\"}",
"logger_name": "org.ssn.app.controller.TestController1",
"thread_name": "http-nio-8080-exec-1",
"level": "DEBUG",
"level_value": 10000,
"ss": "sss"
}
Is there is any way to modify the message attribute's value data type so that we can avoid "\" >back slashes? Because typically i want to put JSON or nested JSON inside message attribute's >value and want to view them without any backslashes