This is a bit rugged, and not thoroughly tested. However it might give you some ideas on how to keep HA log file history. I run HA in a docker container on a Ubuntu linux host, so it is not hard to run a script like this as a tmux session or other automatic startup method. I do not use the dedicated HA OS type installs, so I am not sure how to get this script to run there, hopefully there is a way.
You will need the linux utility ‘inotifywait’, it is part of ‘inotify-tools’ package, various install instructions are documented there:
Good hunting!
#!/usr/bin/env bash
#
# ha_log_rotate.sh
# 202106291016
#
# http://redsymbol.net/articles/unofficial-bash-strict-mode/
# Unofficial Bash Strict Mode (Unless You Looove Debugging)
set -euo pipefail
#
# try and keep a history of homeassistant log files
#
# path to ha log file
HA_PATH="/home/user/homeassistant/home-assistant.log"
# path to logrotate configuration file
ROT_CONFIG="/home/user/ha_log_rotate/ha.conf"
# the ha.conf file contains (note hard coded path to ha log file!!!):
#
#/home/user/homeassistant/home-assistant.log {
# rotate 9
#}
#
# path to logrotate state
ROT_STATE="/tmp/ha.state"
# loop forever
while [[ 1 == 1 ]]
do
# wait for ha log file to be created
while [[ ! -f $HA_PATH ]]
do
sleep 0.5
done
# watch for a close with a write on ha log file and do a log rotate when this occurs
while inotifywait $HA_PATH -e 'close_write';
do
logrotate -f -s $ROT_STATE $ROT_CONFIG
done
done