Skip to main content
The field spec.logConfig can be used to change the log level and log format of zookeeper, bookkeeper, broker and proxy. If logConfig field is configured, the component will use the mount path /mnt/conf/log4j2.yaml to mount the log configuration file, and can dynamically change the log level and log format of the component. The logConfig field has three subfields:
  • level
  • format
  • template
And use the Broker component as the example. First, locate your PulsarBroker object.

level

The level field can be used to change the log level of the component. The value can be one of TRACE, DEBUG, INFO, WARN, ERROR, FATAL, OFF.
spec:
  logConfig:
    level: "DEBUG"
    format: "text"
    template: {}

format

The format field can be used to change the log format of the component. The value can be one of json, text.
spec:
  logConfig:
    level: "INFO"
    format: "json"
    template: {}

template

The template field can totally replace the log4j2 config of the component, which would be useful if you need some customization more than level and format. The value of template is a string, which is the content of the log4j2 config file in yaml format.
spec:
  logConfig:
    level: "INFO"
    format: "text"
    template: |
      Configuration:
        status: INFO
        monitorInterval: 30
        name: pulsar
        packages: io.prometheus.client.log4j2

        Loggers:
          Root:
            {{ if .Level }}
            level: "{{ .Level }}"
            {{ else }}
            level: "INFO"
            {{ end }}
            additivity: true
            AppenderRef:
              - ref: "${sys:pulsar.log.appender}"
                {{ if .Level }}
                level: "{{ .Level }}"
                {{ else }}
                level: "INFO"
                {{ end }}
              - ref: Prometheus
                level: info

Change log level for a specific package

To change the log level for a specific package, first copy the content from the Apache Pulsar log4j2.yaml file into the template field, then modify the log level for the desired package according to your requirements. The following example shows how to change the log level for org.apache.pulsar.broker.service.ServerCnx:
spec:
  logConfig:
    level: "INFO"
    format: "text"
    template: |
      # Copy fully log4j2.yaml file content, then put it here

          Logger:
            - name: org.apache.pulsar.broker.service.ServerCnx
              level: debug
              additivity: false
              AppenderRef:
                - ref: Console

            - name: verbose
              level: info
              additivity: false
              AppenderRef:
                - ref: Console
In this configuration:
  • name: Specifies the package name for which you want to change the log level
  • level: Sets the log level (e.g., debug, info, warn, error)
  • additivity: Set to false to prevent logs from propagating to parent loggers, avoiding duplicate output
  • AppenderRef: Specifies the log output target, such as Console