Has anyone managed to use JSON logging in the k8s ...
# troubleshooting
j
Has anyone managed to use JSON logging in the k8s operator? I’m putting this log4j2.xml file in /flink/config/log4j2.xml
Copy code
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<Configuration xmlns="<http://logging.apache.org/log4j/2.0/config>" strict="true">
    <Appenders>
        <Appender name="StdOut" type="Console">
            <JSONLayout compact="true" eventEol="true" properties="true" stacktraceAsString="true"/>
            <BurstFilter level="WARN" rate="10" maxBurst="100"/>
        </Appender>
    </Appenders>
    <Loggers>
        <Root level="INFO">
          <AppenderRef ref="StdOut"/>
        </Root>
      </Loggers>
</Configuration>
And starting the job with:
Copy code
flinkConfiguration:
    env.java.opts: -Dlog4j.configurationFile=/flink/conf/log4j2.xml
The log4j files are in /opt/flink/lib
Copy code
/opt/flink# ls lib/
... log4j-1.2-api-2.17.1.jar  log4j-core-2.17.1.jarlog4j-api-2.17.1.jar      log4j-slf4j-impl-2.17.1.jar
s
Do you want to enable it for Flink jobs or the operator itself?
j
My intention is to enable it for both.
I managed to solved it for the Job. I didn’t need what I put in the image above. I had to add the package
log4j-layout-template-json
JAR in
/opt/flink/lib
And then add this configuration in the flink.apache.org/FlinkDeployment
Copy code
logConfiguration:
    # Log configuration overrides for the Flink deployment. Format logConfigFileName -> configContent.
    log4j-console.properties: |+
      status = warn
      appender.console.name = CONSOLE
      appender.console.type = CONSOLE
      appender.console.target = SYSTEM_OUT
      
      appender.console.logstash.type = JsonTemplateLayout
      appender.console.logstash.eventTemplateUri = classpath:EcsLayout.json
      
      rootLogger.level = info
      rootLogger.appenderRef.stdout.ref = CONSOLE
Now I have to figure out the operator side of it…