Skip to content

feat(cluster-operator) adding new JsonTemplateLayout support for logging #11543

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

rlanhellas
Copy link

Type of change

Enhancement

Description

Closes #11415

This PR adds support for use the JsonTemplateLayout when configuring log appenders in Log4j2.

Here is a configmap example using this new layout:

kind: ConfigMap
apiVersion: v1
metadata:
  name: strimzi-cluster-operator
  labels:
    app: strimzi
data:
  log4j2.properties: >
    name = COConfig
    monitorInterval = 30

    appender.console.type = Console

    appender.console.name = STDOUT

    appender.console.layout.type = JsonTemplateLayout

    appender.console.layout.eventTemplateUri = file:///opt/strimzi/custom-config/mylayout.json


    rootLogger.level = ${env:STRIMZI_LOG_LEVEL:-INFO}
    
    rootLogger.appenderRefs = stdout

    rootLogger.appenderRef.console.ref = STDOUT


    # Kafka AdminClient logging is a bit noisy at INFO level

    logger.kafka.name = org.apache.kafka

    logger.kafka.level = WARN


    # Keeps separate level for Netty logging -> to not be changed by the root
    logger

    logger.netty.name = io.netty

    logger.netty.level = INFO

  mylayout.json: >
    {
      "instant": {
        "$resolver": "timestamp",
        "pattern": {
          "format": "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'",
          "timeZone": "UTC"
        }
      },
      "someConstant": 1,
      "message": {
        "$resolver": "message",
        "stringified": true
      }
    }

And how the message are printed on console:

{"instant":"2025-06-15T14:51:55.223Z","someConstant":1,"message":"Thread vert.x-eventloop-thread-1 has been blocked for 7802 ms, time limit is 2000 ms"}
{"instant":"2025-06-15T14:51:56.224Z","someConstant":1,"message":"Thread vert.x-eventloop-thread-1 has been blocked for 8804 ms, time limit is 2000 ms"}

Checklist

Please go through this checklist and make sure all applicable tasks have been done

  • Write tests
  • Make sure all tests pass
  • Update documentation
  • Check RBAC rights for Kubernetes / OpenShift roles
  • Try your changes from Pod inside your Kubernetes and OpenShift cluster, not just locally
  • Reference relevant issue(s) and close them after merging
  • Update CHANGELOG.md
  • Supply screenshots for visual changes, such as Grafana dashboards

…erator (strimzi#11415)

Signed-off-by: Ronaldo Lanhellas <ronaldo.lanhellas@gmail.com>
@ppatierno
Copy link
Member

Looking at the PR I think we should have the change for all other components in just one PR.
Said that I think there is the need for testing this. I see we have a LoggingChangeST class where the JsonLayout is tested maybe we should make changes there as well, otherwise we are just adding stuff to Maven without any test.
@im-konge @see-quick tagging you as ST experts.

@im-konge
Copy link
Member

Yes I agree on having some STs for this as well. We have few for the JSON logging in the LoggingChangeST as you mentioned Paolo, so we should have similar for this.

@im-konge im-konge added this to the 0.47.0 milestone Jun 16, 2025
@rlanhellas
Copy link
Author

rlanhellas commented Jun 16, 2025

Fair enough. Let me work on this and update this PR.

@see-quick
Copy link
Member

Fair enough. Let me work on this and update this PR.

If you have any questions regarding the creation of STs, please don't hesitate to ask.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Enhancement]: Add log4j-layout-template-json to the Kafka 4.0 image
4 participants