Custom log file location

It would be nice if we could set a custom path for the home-assistant.log file location.

Here’s another post I created about the topic:

Currently, dumping the home-assistant.log file in the same directory as the config files causes problems when a user tries to back-up the configuration directory. Sure we can set an exclude rule for all .log and .db files, but why would the log files be in the config directory in the first place?

Take Apache for example, the config directory only contains actual config files, and all log files (even custom ones), are written to user-defined log file locations.

I really hate to make a comparison to OH, but it is considered a comparable product. OpenHab has it’s own log file directory, as well as custom log configuration options, documented here:
http://docs.openhab.org/administration/logging.html

Is there any fundamental reason why this can’t be implemented, perhaps something that’s specific to python?

Thanks,

1 Like

For some reason it’s common in python to store the log file next to the config…makes it easier to troubleshoot imho. Because I don’t have to change directories all the time. E.g. flexget does the same. But I agree making it configurable would be good.

~Cheers

1 Like

It should not depend on the programming language but the environment. The location of the logfile is the only thing missing currently to install HA using a “common” Linux layout, that is

  • configuration at /etc/homeassistant (achievable already)
  • database location at /var/lib/homeassitant (achievable alreay)
  • logfiles at /var/log/homeassistant/ the missing part.

Among with an installation of the binaries at /opt/homeassistant or /srv/homeassistant (as suggested) HA would be good to go for a RPM or DEB archive.

Anyway - I support the feature request.

5 Likes

I found this post when looking for how to change the log file directory…
I want to use /var/log where my device has more space than the current location.
I use the init.d daemon as in https://home-assistant.io/docs/autostart/init.d/ and the script has a REDIRECT option for a log file location, but it doesn’t seem to do anything except create a zero length file at that location.
Perhaps that page could be updated so it doesn’t mislead people like me into thinking it does anything!

+1000 Come on guys. This is such a sign of amateurs coding this project. Who puts log files in etc? I’ll tell you who: no one but hass. How do I know? Because i backup my etc changes using etckeeper and no other project or program has changes to the etc dir EVERY…SINGLE…TIME but homeassist. It’s very annoying. I like where you guys are going with this, but this is a serious problem. Fix please.

+1 here, syslog or other remote logging is pretty essential as I’m trying to reduce writes to the Pi SD card as much as possible - I’ve killed two setting this up all ready.
In theory it should be simple to drop python-logging in but I’ll have a look over the code.

I’m going to take a stab at writing this sometime this week because it’s bugging me as well.

My understanding of the way it works now:

  • logs are written to the file [config_path]/home-assistant.log. That’s hard coded in bootstrap.py
  • logs are also written to the screen
  • logging level is either INFO (verbose=True) or WARNING (verbose=False). I’m not sure how this interacts w/ the logging configuration input but I’d guess in the config takes priority.

Goal is to:

  1. allow logs to be written to an arbitrary file
  2. not print logs to the screen unless requested (or print to the screen unless suppressed to keep current behavior)
  3. maybe allow command line configuration of the global logging level. The problem w/ this is that there is already the verbose flag and the config inputs so how would the three interact?

Here’s a proposal:

  1. add command line option “–log /path/to/log” to control the log path.
  2. if --log is specified, turn off screen logging.

Thoughts?

1 Like

Another thing to keep in mind…
Depending on how you’re starting HA, you may also have 2 separate log file locations. For instance, I’m running it as a service, on bare-metal (non-virtual). So the logs being written to the screen normally, are actually being passed to rsyslogd, then filtered out to their own log file.

I guess this doesn’t really matter… Logs are still being written to 2 locations.
The screen (or comand-line output) + home-assistant.log.

My hope is that we can permanently move home-assistant.log to another location, other than the home-assistant directory. So screen / command-line output goes to one file; And messages destined for home-assistant.log can be written to a different, user defined file, outside of the home-assistant directory.

Make sense?

@xstrex I’m confused. Are we talking about logging going to two places, or two different kinds of output? When I run HA, I see the same log message in stdout that I do in the log file. So it looks like the logging object is set to write to both streams. I don’t like that as it means redirecting logging I/O when running as a service. So it would be nice to turn off logging to the screen and just output logging to a (user set-able) file. In that case, any non-logging output would still go to the screen, just not the logging prints.

Let me try and clarify. In my experience, if you download home-assistant, and just give it a basic configuration, nothing special. Then start it up via something like:

./hass -c /opt/homeassistant/

It will:

  1. Output to the screen you’re running it from (I think this is what you’re referencing).
  2. Create a new log file: /opt/homeassistant/home-assistant.log

There is currently no configuration option available to change the log location of the second output (home-assistant.log). My initial hope with this post was to make this configurable. e.g. logfile: /var/log/hass/home-assistant.log

Make sense?

Yes - I’m talking about making both configurable so you can set the log file location (instead of the hard coded one) and have some way to control whether or not output is going to the screen as well.

That makes sense, if you can make that happen, go for it! I’d be happy to help in any way I can.

PR submitted: https://github.com/home-assistant/home-assistant/pull/9422 with a new option --log-file added to the command line. When set, the default config file (CONFIG/home-assistant.log) is not used.

hass --log-file /var/log/home-assistant.log ...
5 Likes

Is this possible to do the same for DB?

Would you mind elaborating? Are you looking for a database specific log?

I mean specifying path to HA’s SQLite database which by default is located in ~/.homeassistant/

You can already do it with db_url in the recorder configuration, e.g.:

recorder:
  db_url: sqlite:////mnt/data/homeassistant/hass.sqlite3

Also note that you need 4 slashes after sqlite: if you want to specify absolute path.

3 Likes

@TD22057 Thanks so much for the PR, I’ve been using this on a new HA install, works great!

Wow, thank you so much :pray:

Hi,

I’m running in Docker, which file do I have to modify to specify my log file location ?

Thanks
V.