ESPLOGD multiple variables not like printf?

I was hoping to directly call HomeAssistant::get()->homeassistant_tag_scanned_to_code in a C++ code (avoiding the .yaml), but I’m not even close to that - I can’t even get a log message to work lol

I have this code

bool KeyVerify::tag_check(const std::string &tag) {
  for (const auto &guest : guest_list_) {
    if (tag == guest.tag()) {
      guest_name_  = "John";
      guest_role_ = "work";
      ESP_LOGD("key_verify approves %s", guest_name_.c_str());
      ESP_LOGD("role: %s   using tag", guest_role_.c_str());
      ESP_LOGD("but both %s, together %s, is a problem", guest_name_.c_str(), guest_role_.c_str());
      return verified_ = true;
      } 

yielding an unexpected result

[14:01:56][D][key_verify approves %s:036]: John
[14:01:56][D][role: %s   using tag:037]: work
[14:01:56][D][but both %s, together %s, is a problem:038]: John

so I’m a bit disappointed in my progress so far lol. It’s a basic thing, but it wasn’t mirroring the syntax of printf (and I thought it did).

but while you’re here, if you could point me in the appropriate direction for what to #include to and how to format homeassistant_tag_scanned_to_code() to send directly to the API, that would also be much appreciated! :slight_smile:

ESP_LOGD(TAG, "but both %s, together %s, is a problem", guest_name_.c_str(), guest_role_.c_str());

Notice that I have a TAG variable as the first parameter. this is defined as

static const char* TAG = "MyModule";

Try that, as your code will use the string as the TAG, which is not what you want.

The docs:
https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/log.html

1 Like