Log rotation - Docker Compose

I’ve seen a LOT of unanswered topics, ranging from recent to many years old, all asking about log rotation. Some have a few replies about some command line options, but none seem to have a definitive answer of what works, so let’s hope this can be the end all topic.

I run HA in a Docker container, configured in a Docker Compose file. For the second time now, I ran into the issue where my server started being all weird, no longer serving webpages, etc… Unlike the last time (which was no fun I can tell you), this time I remembered that this was probably caused by a massive HA log, and it was. I had 24GB of log data. I really don’t want to go through this again, so:

How do we setup log rotation when you have configured your HA container in Docker Compose?

Also, why isn’t log rotation simply handled in the logger component in the config yaml, so it’s the same for everyone?


Edit: I knew it wasn’t just those logs! I kept on checking, and found [random-string-of-numbers-and-letters]-json.log. A whopping 58GB. Seriously, how can people run HA on something like an RPi with a small SD-card if this keeps happening? I’m fortunate enough to have a lot of storage available, but this is insane…

Is this zwave?

I turn off most logging unless needed
You can create some command line integration to perform deletion of logs and monitor their size