It would be handy to have a service that would let you write to the log file. An automation could use the service to write a comment, or the current value of some entity, to the log.
Before the advent of integrated debuggers, writing comments and variable values to the log was a time-honored way to debug code. In python you can use logger.info for this purpose. However, there’s no native way to do it in an automation (that I know of).
In this thread, the author’s automation calls a script which, in turn, writes the desired value or comment to the log file.
That’s a neat workaround but must be used judiciously because you can’t call a script that’s already running.
The proposed feature would look something like this when used in an automation:
action:
- service: logwriter.info
data_template:
message: "Front door is {{ states('binary_sensor.front_door') }}"
That’s close except the goal is write to syslog. However, your suggestion made me look more closely at the Notification component and its many platforms including: Syslog!
I haven’t had a chance to try it yet but it looks very promising.
However, displaying the logbook (which is sourced from the SQLite DB) is uncomfortably slow (on my system) whereas displaying the contents of syslog is dramatically faster. Nevertheless, I appreciate your help.
action:
- service: system_log.write
data_template:
message: "The state of the switch is {{states('switch.something')}}"
level: info
It also resolves a problem I encountered while using the syslog notification platform, namely it does not work when Home Assistant runs in a docker container.
I’ve concluded it has to do with the fact the syslog notification platform uses the syslog python library whereas most everything else, including the system_log component, use python’s logging library. For whatever reason, Home Assistant as a docker container doesn’t seem to support the syslog library.
I am running as a container also and I tried this system_log.write service but I see nothing. Is it just writing it to the standard log? Can it write to the container console?
2020-01-26 14:21:30 INFO (MainThread) [homeassistant.components.automation] Executing html notification test
2020-01-26 14:22:06 INFO (MainThread) [homeassistant.components.automation] Executing html notification test
2020-01-26 14:22:08 INFO (MainThread) [homeassistant.components.automation] Executing html notification test
2020-01-26 14:22:09 INFO (MainThread) [homeassistant.components.automation] Executing html notification test
2020-01-26 14:22:11 INFO (MainThread) [homeassistant.components.automation] Executing html notification test
How do I access the syslog? I am running on a raspberry pi and via the web interface I have several logs to choose from but its not clear to me if any are the actual syslog