[FR] Log file rotation/truncation for Logger Component

TL;DR - Implement a Log File Rotation/Truncation feature for the Logger component which can be scheduled based on time (every 24 hours, X number of days, etc.) or file size (50MB, 100MB, etc.).

As individual Home Assistant instances become more complex, the need to use logger data becomes more and more frequent. In many instances, errors occur unknowingly which necessitates a review of home-assistant.log. In some cases, however, home-assistant.log becomes so large that retroactively viewing a large log file becomes difficult.

The implementation of scheduled log rotation/truncation would alleviate such issues whilst preventing HA from grinding to a halt due to an enormously sized log file.

I’d like to add support for this feature.

I’d also ask for other log files to be rotated as well: e.g. OZW_Log.txt

I think this feature is especially important as a self-defense mechanism to prevent bugs like:

from possibly corrupting the HA install.

Starting from version 0.107 there is no easy way to pass a --log-rotate-days argument to a HA bootstrap script inside a Docker container. They switched to s6 supervisor and the only option I see is to replace a service file (https://github.com/home-assistant/core/blob/bd28a9f99bd927d4c01f08ac78048a49220d0d12/rootfs/etc/services.d/home-assistant/run). Theoretically you can setup logrotate, but I don’t know how HA will react on truncated log file.
Previously you could just set up ["python", "-m", "homeassistant", "--config", "/config", "--log-rotate-days", "4"] as a command and your logs will be rotated each 4 days.