# Does confluent kafka (cp-kafka) support Log4j RollingFileAppender with Time/Size Based Triggering Policy & Rollover Strategy? Doesn't seem to work

**URL:** <https://forum.confluent.io/t/does-confluent-kafka-cp-kafka-support-log4j-rollingfileappender-with-time-size-based-triggering-policy-rollover-strategy-doesnt-seem-to-work/5686>\
**Category:** Containers\
**Created:** [3 August 2022 20:36 UTC](https://forum.confluent.io/t/does-confluent-kafka-cp-kafka-support-log4j-rollingfileappender-with-time-size-based-triggering-policy-rollover-strategy-doesnt-seem-to-work/5686 "2022-08-03T20:36:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![lmk](https://avatars.discourse-cdn.com/v4/letter/l/b5a626/32.png) [@lmk](https://forum.confluent.io/u/lmk)\
**Post date:** [3 August 2022 20:36 UTC](https://forum.confluent.io/t/does-confluent-kafka-cp-kafka-support-log4j-rollingfileappender-with-time-size-based-triggering-policy-rollover-strategy-doesnt-seem-to-work/5686/1 "2022-08-03T20:36:25Z")

</div>

I am using the [Confluent Community](https://hub.docker.com/layers/cp-kafka/confluentinc/cp-kafka/7.0.2/images/sha256-dd2b682e17cd606f26c2232b048a171d59a976db61c33e7a6c7da7ad08ff66e3?context=explore) Docker Image for Apache Kafka & trying to have the Kafka logs rolled over daily with a Time & Size Based Triggering Policy & Rollover Strategy.

As mentioned in the [docs](https://docs.confluent.io/platform/current/installation/docker/development.html#log-to-external-volumes), I have extended the image & set it up with a Log4j configuration via properties.

However i see that only basic configuration of `org.apache.log4j.RollingFileAppender` **without any daily rolling or policies** appears to work (the commented out config settings in the property file below).

The examples on the docs also appears to use only the very old Log4j1.x `org.apache.log4j.DailyRollingFileAppender` which as we know (and as per 1.x docs) should not even be used. I am not even sure if Kafka packaged `apache-log4j-extras` along with log4j1.x earlier.

Below are the Dockerfile & log4j properties i am using. Any of you guys had any luck with it? Am i doing something incorrectly in the below?

Dockerfile:

```auto
FROM confluentinc/cp-kafka:7.0.2
COPY log4j.properties.template /etc/confluent/docker/log4j.properties.template

```

log4j properties:

````auto
log4j.rootLogger={{ env["KAFKA_LOG4J_ROOT_LOGLEVEL"] | default('INFO') }}, stdout, rollingFile

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=[%d] %p %m (%c)%n

#log4j.appender.rollingFile=org.apache.log4j.RollingFileAppender
#log4j.appender.rollingFile.File=/var/log/kafka/kafka-server.log
#log4j.appender.rollingFile.filePattern=/var/log/kafka/kafka-server-%d{yyyy-MM-dd}-%i.log
#log4j.appender.rollingFile.layout=org.apache.log4j.PatternLayout
#log4j.appender.rollingFile.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %m%n
#log4j.appender.rollingFile.MaxFileSize=5KB
#log4j.appender.rollingFile.MaxBackupIndex=15
#log4j.appender.rollingFile.append=true

log4j.appender.rolling.type=RollingFile
log4j.appender.rolling.name=rollingFile
# Below is the default..just making explicit.
log4j.appender.rolling.append=true
log4j.appender.rolling.fileName=/var/log/kafka/kafka-server1.log
log4j.appender.rolling.filePattern=/var/log/kafka/kafka-server1-%d{yyyy-MM-dd}-%i.log
log4j.appender.rolling.layout.type=PatternLayout
log4j.appender.rolling.layout.pattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %m%n
log4j.appender.rolling.policies.type=Policies
log4j.appender.rolling.policies.time.type=TimeBasedTriggeringPolicy
# Below is the default..just making explicit.
log4j.appender.rolling.policies.time.interval=1
log4j.appender.rolling.policies.size.type=SizeBasedTriggeringPolicy
log4j.appender.rolling.policies.size.size=20MB
log4j.appender.rolling.strategy.type=DefaultRolloverStrategy
# Delete all files older than 15 days
log4j.appender.rolling.strategy.delete.type=Delete
log4j.appender.rolling.strategy.delete.basePath=/var/log/kafka/
log4j.appender.rolling.strategy.delete.ifLastModified.type=IfLastModified
log4j.appender.rolling.strategy.delete.ifLastModified.age=15d

{% set loggers = {
  'kafka': 'INFO',
  'kafka.network.RequestChannel
```: 'WARN',
  'kafka.producer.async.DefaultEventHandler': 'DEBUG',
  'kafka.request.logger': 'WARN',
  'kafka.controller': 'TRACE',
  'kafka.log.LogCleaner': 'INFO',
  'state.change.logger': 'TRACE',
  'kafka.authorizer.logger': 'WARN'
  } -%}

{% if env['KAFKA_LOG4J_LOGGERS'] %}
{% set loggers = parse_log4j_loggers(env['KAFKA_LOG4J_LOGGERS'], loggers) %}
{% endif %}

{% for logger,loglevel in loggers.items() %}
log4j.logger.{{logger}}={{loglevel}}
{% endfor %}

````

The official link from Confluent that still points to the usage of very old DailyRollingFileAppender. Perhaps Confluent still recommends using this i guess even though Log4j recommends against using it…

Thanks

---

<div class="post-metadata">

**Author:** ![OneCricketeer](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.confluent.io/onecricketeer/32/1551_2.png) [@OneCricketeer](https://forum.confluent.io/u/OneCricketeer)\
**Post date:** [24 November 2022 04:24 UTC](https://forum.confluent.io/t/does-confluent-kafka-cp-kafka-support-log4j-rollingfileappender-with-time-size-based-triggering-policy-rollover-strategy-doesnt-seem-to-work/5686/2 "2022-11-24T04:24:38Z")

</div>

Ideally, you’d have your container always log to stdout. Use other tools like Filebeat or Fluentd to capture Docker logs and roll into files.
