Open weeco opened 5 years ago
I received similar request months ago. My solution is by providing a logback.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<property name="pattern" value="{"ProdUser":"kafkahq", "App_Time": "%d", "LogLevel": "%p", "class": "%logger{63}:%L", "message": "%replace(%m){'[\r\n]+', '\\n'}%nopex"}%n" />
<appender name="consoleAppender" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${pattern}</pattern>
</encoder>
</appender>
<logger name="jsonLogger" additivity="false" level="DEBUG">
<appender-ref ref="consoleAppender"/>
</logger>
<root level="INFO">
<appender-ref ref="consoleAppender"/>
</root>
</configuration>
and start the application with java - -Dlogback.configurationFile=file:/etc/kafkahq-logback/logback.xml
If you also use helm-chart, my log configuration is in a configmap, and the above is placed in container command
An option to enabled structured JSON logging is desirable as we can parse this information in our environment, so that we can better process logs.