Logger.log name reference

Can the name be automatically assigned to the log as follows?:

binary_sensor:
  - platform: gpio
    name: "something"
    on_press:
      then:
        - logger.log:
            format: "name: %s"
            args: [ ??? ]

So it prints ‘name: something’, or even better to use it as logger tag.

So just what the tag: option does?

  • tag (Optional, string): The tag (seen in front of the message in the logs) to print the message with. Defaults to main.

Yes, like the tag, considering the output prefix.
But how to refer to the ‘name’?

I’m not sure what you are trying to achieve… You can add the sensor name to the log output using lambda logging, but since you need to refer to the id of the component why bother? Just hard code the name using tag:.

ESP_LOGD(id(sensor_id).name , "formatted message of some kind using C++ syntax");

I’m hoping to get this automated, resolving the name of the current scope, without giving it by hand. So to get something like ‘id(this).name’.
Assume there are many of copies of initial example:

- platform: copy
  name: "other"

So the log would print ‘name: something’ for the initial example and ‘name: other’ for this one.
Or do I expect too much from this? No questions then.

Hmm - no idea. Maybe chat to the devs on discord unless you can garner something from the docs: ESPHome: /opt/build/esphome/esphome Directory Reference