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:
- allow logs to be written to an arbitrary file
- not print logs to the screen unless requested (or print to the screen unless suppressed to keep current behavior)
- 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:
- add command line option “–log /path/to/log” to control the log path.
- if --log is specified, turn off screen logging.
Thoughts?
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:
- Output to the screen you’re running it from (I think this is what you’re referencing).
- 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 ...
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.
Wow, thank you so much
Hi,
I’m running in Docker, which file do I have to modify to specify my log file location ?
Thanks
V.
This post is 3 years old, probably want to make a new post to get relevant information.
@Vartkat id you every get this sorted out? I am looking for exactly the same since I also run HA in a Docker container.