Camunda 7.17 json format logs

Hi all I have installed Camunda engine (Camunda BPM runtime) community edition V 7.17.0 and I am trying to format logs as json however I can’t find a proper documentation on how to do it, my installation is inside a K8s cluster.

Thanks in advanced

What distribution of camunda you are using ? Is this Tomcat , Camunda run or Custom springboot based implementation. The answer will differ based on this info.

for spring boot JSON logging add following dependency in pom.xml

    <dependency>
      <groupId>net.logstash.logback</groupId>
      <artifactId>logstash-logback-encoder</artifactId>
      <version>7.3</version>
    </dependency>

Add logback-spring.xml in src/main/resources

Content :

<configuration>
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
            <providers>
                <timestamp>
                    <timeZone>UTC</timeZone>
                </timestamp>
                <pattern>
                    <pattern>
                        {
                        "level": "%level",
                        "logger": "%logger",
                        "message": "%message",
                        }
                    </pattern>
                </pattern>
                <stackTrace>
                    <throwableConverter class="net.logstash.logback.stacktrace.ShortenedThrowableConverter">
                        <maxDepthPerThrowable>30</maxDepthPerThrowable>
                        <maxLength>2048</maxLength>
                        <shortenedClassNameLength>20</shortenedClassNameLength>
                        <rootCauseFirst>true</rootCauseFirst>
                    </throwableConverter>
                </stackTrace>
            </providers>
        </encoder>
    </appender>

    <!-- camunda -->
    <!-- <logger name="org.camunda" level="info"/> -->

    <!-- common dependencies -->
    <!-- <logger name="org.apache.ibatis" level="info" /> -->
    <!-- <logger name="javax.activation" level="info" /> -->
    <!-- <logger name="org.springframework" level="info" /> -->
    <!-- <logger name="org.apache.catalina" level="info" /> -->


    <!-- <logger name="org.apache.jasper.servlet.TldScanner" level="debug"/> -->

    <!-- avoid many log entries from failing jobs -->
    <!-- <logger name="org.camunda.bpm.engine.jobexecutor" level="off" /> -->
    <!-- <logger name="org.camunda.bpm.engine.context" level="off" /> -->


    <!--
      <logger name="org.camunda.bpm.engine.impl.persistence.entity" level="debug" />
      <logger name="org.camunda.bpm.engine.history" level="debug" />
      <logger name="org.camunda.bpm.engine.bpmn.parser" level="debug" />
      <logger name="org.camunda.bpm.engine.bpmn.behavior" level="debug" />
      <logger name="org.camunda.bpm.engine.cmmn.transformer" level="debug" />
      <logger name="org.camunda.bpm.engine.cmmn.behavior" level="debug" />
      <logger name="org.camunda.bpm.engine.cmmn.operation" level="debug" />
      <logger name="org.camunda.bpm.engine.cmd" level="debug" />
      <logger name="org.camunda.bpm.engine.persistence" level="debug" />
      <logger name="org.camunda.bpm.engine.tx" level="debug" />
      <logger name="org.camunda.bpm.engine.cfg" level="debug" />
      <logger name="org.camunda.bpm.engine.jobexecutor" level="debug" />
      <logger name="org.camunda.bpm.engine.context" level="debug" />
      <logger name="org.camunda.bpm.engine.core" level="debug" />
      <logger name="org.camunda.bpm.engine.pvm" level="debug" />
      <logger name="org.camunda.bpm.engine.metrics" level="debug" />
      <logger name="org.camunda.bpm.engine.util" level="debug" />
      <logger name="org.camunda.bpm.application" level="debug" />
      <logger name="org.camunda.bpm.container" level="debug" />
    -->

    <root level="info">
        <appender-ref ref="STDOUT" />
    </root>
</configuration>

You may make changes in xml file as per your needs of logging.

Hi sorry for the late response I am using.
Camunda BPM Runtime
V 7.17.0
Community edition
With a PostgreSQL DB (v 14.7)

I got from docker hub the camunda-bpmn-platform:tomcat-7.17.0

I am running it in a k8s cluster and I get the logs but with no json format and I would like to get all logs in json.

One extra help how can I achieve get logs every time a transaction is being processed.

Thanks in advanced.

Sorry for late reply but I was able to achieve this by extending base Camunda image for Camunda version 7.20 amardeep2006/camunda-tomcat-json-logging-docker: Implement JSON logging in Official Camunda Docker image (github.com)

I have done intentionally for Camunda 7.20 version since this is latest stable Community version.

Hi @fdominguezg : I have installed Camunda engine in docker way… Herewith providing you step-by-step instructions on how did I change the text formatted logs into JSON formatted logs…

As I identified that the base v7.17.0 image of Camunda is using Java-Util-Logging (JUL) by default, we need to do the following changes,

  1. Prepare the Dockerfile with following contents,
FROM camunda/camunda-bpm-platform:7.17.0

ADD https://repo1.maven.org/maven2/net/logstash/logback/logstash-logback-encoder/5.2/logstash-logback-encoder-5.2.jar /camunda/lib
ADD https://repo1.maven.org/maven2/ch/qos/logback/logback-classic/1.1.2/logback-classic-1.1.2.jar  /camunda/lib
ADD https://repo1.maven.org/maven2/ch/qos/logback/logback-core/1.1.2/logback-core-1.1.2.jar /camunda/lib
ADD https://repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-annotations/2.9.0/jackson-annotations-2.9.0.jar /camunda/lib
ADD https://repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-core/2.9.5/jackson-core-2.9.5.jar /camunda/lib
ADD https://repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-databind/2.9.5/jackson-databind-2.9.5.jar /camunda/lib
ADD https://repo1.maven.org/maven2/org/slf4j/jul-to-slf4j/1.7.7/jul-to-slf4j-1.7.7.jar /camunda/lib
ADD https://repo1.maven.org/maven2/org/slf4j/slf4j-api/1.7.7/slf4j-api-1.7.7.jar /camunda/lib

COPY logging.properties /camunda/conf/
COPY logback.xml /camunda/configuration/
COPY setenv.sh /camunda/bin/setenv.sh

USER root
RUN chmod -R 775 /camunda/lib/

ENV JAVA_OPTS="-Dlogback.configurationFile=/camunda/configuration/logback.xml"
  1. Prepare the logback.xml file with following contents,
<configuration>
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder class="net.logstash.logback.encoder.LogstashEncoder" />
    </appender>

    <root level="INFO">
        <appender-ref ref="STDOUT" />
    </root>
</configuration>
  1. Prepare/change the logging.properties file with following contents,
#Include Slf4j bridge handler
handlers = org.slf4j.bridge.SLF4JBridgeHandler

# Remove the ConsoleHandler as it will print logs with both text & JSON format
.handlers = 1catalina.org.apache.juli.AsyncFileHandler, org.slf4j.bridge.SLF4JBridgeHandler
  1. Prepare the setenv.sh file with following contents,
# Sets the initial classpath to have the needed JUL -> SLF4J jars + the logstash/Logback libraries
CLASSPATH=/camunda/lib/*