Just to make some things clear: I'm talking about the process logfile that contains the stdout and stderr messages.
This is my systemd unit file:
[Unit]
Description=Apache Kafka server
Documentation=http://kafka.apache.org
Requires=network.target remote-fs.target
After=network.target remote-fs.target
[Service]
Type=simple
PIDFile=/var/run/kafka.pid
User=kafka
Group=kafka
Environment="JAVA_HOME=/usr/lib/jvm/jre"
Environment="KAFKA_LOG4J_OPTS=-Dlog4j.configuration=file:/var/log/kafka"
ExecStart=/opt/kafka/bin/kafka-server-start.sh /opt/kafka/config/server.properties
ExecStop=/opt/kafka/bin/kafka-server-stop.sh
Restart=on-failure
SyslogIdentifier=kafka
[Install]
WantedBy=multi-user.target
Note that I added the KAFKA_LOG4J_OPTS environment variable.
However, that doesn't seem to do anything. This is the output, when I try to start my service:
Feb 11 00:55:30 kafka01 kafka[4047]: mkdir: cannot create directory ‘/opt/kafka/bin/../logs’: Permission denied
Feb 11 00:55:30 kafka01 kafka[4047]: OpenJDK 64-Bit Server VM warning: Cannot open file /opt/kafka/bin/../logs/kafkaServer-gc.log due to No such file or directory
Feb 11 00:55:30 kafka01 kafka[4047]: log4j:WARN No appenders could be found for logger (kafka.Kafka$).
Feb 11 00:55:30 kafka01 kafka[4047]: log4j:WARN Please initialize the log4j system properly.
So, can please someone tell me the correct way to change the location of the kafka log file? KAFKA_LOG4J_OPTS doesn't work, KAFKA_LOG_DIR doesn't work either (=I was hoping kafka implemented this similar to zookeeper). The kafka documentation doesn't tell me either.
For other unfortunate lads like my, you need to modify
LOG_DIR
environment variable (tested for Kafkav0.11
).If you open script
kafka-server-start
or/usr/bin/zookeeper-server-start
, you will see at the bottom that it callskafka-run-class
script. And you will see there that it usesLOG_DIR
as the folder for the logs of the service (not to be confused with kafka topics data).As eddyP23 mentioned in previous response... kata-run-class uses LOG_DIR
However there is logic in it to use Script directly parent folder if LOG_DIR variable is not set.
So if your scripts are in kafka/bin folders where you are starting kafka... then logs will be present in kafka/log
Maybe not actually the answer to the questions but I've arrived here searching for where kafka stores application logs, not producers/consumers data. IMO calling this data logs is really bad naming.
I've deployed a Kafka cluster on GCP Kubernetes engine and I wanted to view the logs of the application and here is how I did it.
1- Get the pods
2- Connect to one of the Kafkas pods with interactive command
3- Echo $, in command line type
echo $
and press the tab button several times ... you will get a list of all defined environment variables, search for$KAFKA_HOME
or just typeYou will get to:
The log directory is what I was looking for ...