tchiotludo / akhq

Kafka GUI for Apache Kafka to manage topics, topics data, consumers group, schema registry, connect and more...
https://akhq.io/
Apache License 2.0
3.3k stars 638 forks source link

Add JSON log format #91

Open weeco opened 5 years ago

weeco commented 5 years ago

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.

HungUnicorn commented 4 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="{&quot;ProdUser&quot;:&quot;kafkahq&quot;, &quot;App_Time&quot;: &quot;%d&quot;, &quot;LogLevel&quot;: &quot;%p&quot;, &quot;class&quot;: &quot;%logger{63}:%L&quot;, &quot;message&quot;: &quot;%replace(%m){'[\r\n]+', '\\n'}%nopex&quot;}%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