Help with logrotate

I have a RPi3 running AIO installer. I tried to set up logrotate to rotate the home-assistant.log and more importantly, OZW_Log.txt. I have 16 nodes on my Z-Wave network and the log file is very chatty.

I tried setting it up using pretty standard settings

/home/homeassistant/.homeassistant/home-assistant.log 
/home/homeassistant/.homeassistant/OZW_Log.txt
{
  daily
  rotate 3
  compress
  su homeassistant.homeassistant
}

and found that while the file rotates successfully, nothing is written to the new zero-length file. I also tried using the copytruncate option and that created corrupted files both for the rotated logs and the active log. Has anyone successfully set up logrotate with either OZW_Log or home-assistant.log and can share their configuration? Thanks.

Allow me to answer my own question. The ‘copytruncate’ option of logrotate seems to address this for home-assistant.log. Unfortunately Open Z-Wave has an open issue where there is no way to rotate the log without restarting the Z-Wave stack. OZW holds its logfile open at all times while running and cannot currently be convinced otherwise. The only solution is apparently to periodically restart HA.

Which brings me to a new question, does anyone know how to reduce the log level of OZW from HA?

Came across this post looking for a similar answer for the HA log - seems to work well. Unfortunately my sensor for monitoring the logfile size seems cumulative as it keeps increasing instead of resetting back:

image

192K    home-assistant.log
544K    home-assistant.log.1.gz

EDIT: Ended up using an automation to set the sensor to 0 every 24 hour. Works for me.

I have the similar challenge, namely copytruncate options results corrupted log file with many zeros at the beginning of the file with about 25% probability (so not always). There is similar logrotate.d configuration here but I think it will result the same issue. For proper solution one would either need to pipe all logs through a helper that will route the logs to a proper file, or some way to notify HASS that logfiles should be re-opened.

P.S. Separate/dedicated OZW logs are a big surprise as that component should re-use standard logging approach.

By default, hass rotates logs on each restart. Ozw is deprecated, you should switch to zwavejs. Zwavejs2mqtt also can rotate logs by default.

That’s clear, thanks, but there is a demand to rotate logs on a strictly monthly basis, and of course, without restart.

Ok, then make a feature request for that. Otherwise try to employ one of the methods above.

Thanks, I have created a feature request.