How to redirect Home Assistant log from Docker to /var/log

Tags: #<Tag:0x00007f739ea7f210>

On my system /var/log is on ramdisk in order to avoid writes to my SD card. By default, the Home Assistant container writes logs to /etc/homeassistant/home-assistant.log, that’s nonstandard and incorrect on Linux systems.

One can redirect the log file like this:

  1. Let systemd-tmpfiles know that Home Assistant needs a folder in /var/log on each boot. Open /etc/tmpfiles.d/home-assistant.conf and add these line, save it:

    d /var/log/homeassistant 0755 root root - -
    f /etc/homeassistant/home-assistant.log 0644 root root - -
    
  2. Create the container with the log mounted into the correct location, the important addition is -v /var/log/homeassistant/home-assistant.log:/config/home-assistant.log

    If you haven’t yet instructed systemd-tmpfiles to create /var/log/homeassistant/homeassistant.log make sure to do it manually, otherwise Docker will try to be smart and create homeassistant.log as a directory :roll_eyes:.

    sudo docker run --init -d --name="home-assistant" -e "TZ=[your timezone]" -v /etc/homeassistant:/config  -v /var/log/homeassistant/home-assistant.log:/config/home-assistant.log [fill in the rest according to your container configuration and the documentation]
    

(Before you ask, no, just a symlink from /etc/homeassistant to /var/log doesn’t work)

If you haven’t, you probably also wish to instruct Docker to use journald or rsyslog as its logging destination, Docker too creates its own log file.

2 Likes

Use logging configuration of docker to store it to the right place (I changed it to log into syslog)

That’s docker’s log in /var/lib/docker/containers/{container hash}/{something}.log, yes that disappears nicely after Docker has been reconfigured, however it does not affect the home-assistant.log file that’s created in /config/home-assistant.log (mounted to /etc/homeassistant/). Because even if Docker itself is instructed otherwise that file is created by Home Assistant and it’s mandatory.

If you’re writing a Community Guide, it’s preferable to avoid including personal opinions and similar editorializing. It’s a guide, not an op-ed.

For example, I removed your original statement about how you found the default configuration to be “annoying”. You subsequently felt the need to amend it and add “that’s not good”.

“Annoying” and “that’s not good” are opinions based on your specific requirements. There’s nothing inherently wrong with the file’s location; it’s consistent with other installation methods.

If you feel strongly about the file’s location, compose a regular post, or a Feature Request, expressing your opinions and why it should be located elsewhere.

Actually you’re incorrect. /etc is rather officially not for logs, yet that is the recommended default. I could have written it much more sternly what I think of nonstandard behaviour than just “annoying”.

That doesn’t justify editorializing within a Community Guide. Simply compose a Feature Request suggesting it be relocated to comply with logging standards.

It probably has been requested, but while it’s not been implemented, it’s not incorrect to call it incorrect.

Has it “probably been requested”?

If you believe it fails to comply with logging standards, simply state that (with a link to a reference supporting the claim). That serves to educate the reader far better than expressing a personal opinion about its location.


EDIT
… and you’ve amended your post accordingly. Thank you!

Yeah, logging system improvements have been requested:

Probably there are more, I found these with a quick search.

1 Like