Log rotate

Whenever a component or configuration option results in a warning, it will be stored in home-assistant.log in the configuration directory. This file is reset on start of Home Assistant.
Can the log file be rotated instead, with 2-3 previous versions kept by default?

Already requested, but I voted.

Yes please, I was thinking the same thing the other day. Even just keeping one iteration, .log.old

Check this out. It is working fine in my installation.

1 Like

Ok, but my problem is this when HA crashes I can’t even get onto the host via SSH, so I end up power cycling the Pi. When everything comes back up I have no visibility of what went wrong :frowning:

Well if you can’t SSH than that is probably a problem on the linux host side, not HA itself.

I am using Home Assistant OS

Agree, it would be great if at least the previous log is saved when the new log is created. This is especially helpful in cases where the complete system hangs or seems unresponsive: upon new boot the log is empty so good luck with troubleshooting…

For me, the Minimum Viable Product here would be to copy/rename the existing home-assistant.log file to previous.log (or something similar) before generating the new log file.

In this case you always have 1 previous log available if your system has been shut down ungracefully.

This should be a native configuration.

I’ve enabled logging for a component since a while and I now have almost 900MB in a single log file:
898895822 Apr 5 23:46 home-assistant.log

I am now adding logrotate to my Terminal+SSH configuration.

apks:
  - monit
  - py3-monotonic
  - screen
  - etckeeper
  - logrotate

And I created /etc/logrotate.d/ha:

/config/home-assistant.log {
        copytruncate
        daily
        rotate 14
        compress
        delaycompress
        missingok
        notifempty
        sharedscripts
}
1 Like

Looking good. Only sharedscripts seems a noop to me without any defined scripts.

To safe space in HA backups I’d use olddir to move the old log files outside the config directory. As that’s the main reason for me I opt for size.

/config/home-assistant.log {
        copytruncate
        size 100k
        rotate 10
        compress
        delaycompress
        missingok
        notifempty
        oddir /var/log/homeassistant_old
}

Actually all logs/log-entries are stored( not sure about the quota ) in the linux “journal” accessible with “advance terminal & ssh”
However it’s tedious and not user friendly, So a 1,2-3 days or even 5, of easy readable logs, Could be a good/user friendly “feature”, That is, if people are aware of the “space” required , which can be alot , if the system have spewed +100000 rows ( i’ve heard of logfiles Quite Large ) ( that’s 1 reason why the files are rotated, and the “journals” used to store ( in another “smaller” format )
Tedious, but not impossible.

The log is rotated now. home-assistant.log becomes home-assistant.log.1 on restart. There is also home-assistant.log.fault (not sure when that is generated)

1 Like

I Know, and what i mend/said also, and the .fault-file actually “sometimes” contains information ( i guess in “severe” cases, don’t know which “flag” will cause log in this

Right, and if HA comes up, but seamlessly/or not working properly, people restart/reboot again, or the system is in such a “shape” it does reboot, or crash again, so basically , The.log.1 is in many scenarios useless ( because this get replaced in next restart/reboot )

It would be better if it went a little deeper, say to .5.

But some people will run out of space if too many are saved. Being able to set it would be ideal, say

logger:
  keep: 5
1 Like

Yeah , thats a big AO, people have to learn about the consequences of their actions, such as keeping backups forever, logging/writing every tiny details, in DB, and storing logfiles.

Actually such basic Info(knowledge) should be “punched” in (somehow/somewhere), as many new users , doesn’t know the impact or relevance

BTW I have been preaching about this for a while now

Yes, ive seen a few (including this “old” FR) on this matter, and i prefer a simple solution, easy to implement, upon users responsibility :+1:

Not that i have had much reasons to look in old logs, if any , but just because it’s yours :grin: “sleeping” FR, i give it +1 ( For proposal 1 )

PS: Maybe Spook can accomplice such script, after all He is our Homie :smile:

1 Like