Logger.log service to debug automations

Playing around with automations currently I found it kind of bugging not having a service to easily print something to the log to see what my automation is doing. As a workaround I use notify.file, but it seems much simpler if I could do something like:

...
  action:
    service: logger.debug
    message: "automation has been triggered"
...

The output of that would then just show up as a (debug) log message along with all the other logs and no need for a dedicated logging helper. Of course templating would be handy so we could display all the fancy stuff.

I was looking for exactly the same thing. Thanks for pointing out the workaround (which I need to test but I hope this is juts an extra action to add).

It would also be interesting to trigger the debug possibly as part of a template. When I have if else conditions, I would be happy to be able to log when I am in one of the blocks (the if or the else)

I use an input_text:

action:
  - service: input_text.set_value
    data_template:
      entity_id: input_text.debug
      value: Text here

So that I can always have the informations, for instance, to know the value of a sensor on the frontend at any time I use this automation:

alias: System - Debug
hide_entity: true
initial_state: 'on'
trigger:
  - platform: time_pattern
seconds: '*'
action:
  - service: input_text.set_value
data_template:
  entity_id: input_text.debug
  value: A '{{ states.device_tracker.sellerone.state }}'

Hope this can be helpful :slight_smile:
The log writing is also very useful!

Thanks
Andrea

Quick update, I just tested your solution and unfortunately it is not working, maybe it was on an old version.

For whoever ends up here, mine should be working fine, just make sure to create the input_text called debug :slight_smile:

Ok, looked up two hours and finally found something.

which is part of the “system_log.write” service. One can test that within the service panel of HA (the leftmost tiny icon in the side panel).
Screenshot%20from%202019-05-06%2010-29-36

Which shows up in config/home-assistant.log as:
2019-05-06 10:26:29 ERROR (MainThread) [homeassistant.components.mylogger] 42

A automation “rule” would look like this:

- alias: my verbose automation rule
  trigger:
    ...
  action:
    - service: system_log.write
      data_template:
        level: error
        logger: homeassistant.components.mylogger
        message: "sensor state: {{ states.sensor.pv_raw_a.state|int }}"

If one would like to see messages of log level below “error” (e.g. debug), she would have to set the log level in the configuration.yaml like:

logger:
  default: error
  logs:
    homeassistant.components.mylogger: debug
3 Likes

Should be closed? There is logbook.log available as a service.

    - service: logbook.log
      data_template:
        name: HomeKit
        message: 'started'

or system_log.write as explained above

1 Like

For anyone who stumbles across this thread: You can also write to the log file (/config/home-assistant.log on my system) with:

 - service: system_log.write
        data_template:
          level: debug
          logger: my_debug
          message: "Debug Messsage here"

This requires the “debug” be enabled for target “my_debug” in the config file under “logger:”, such as:

logger:
   logs:
      my_debug: debug

6 Likes