Printing String Array Values through logger.log: Inconsistent results (looks like 2 bugs!)

I’m learning how to use an array of global variable Strings, so I’m doing tests and using logger.log to print my test results. I’m getting inconsistent results with the output. I have a normal single string and an array of 5 strings:

globals:
  - id: TestText
    type: String
    initial_value: '"Original Text"'
  - id: TestArray
    type: String[5]
    initial_value: '{"One", "Two", "Three", "Four", "Five"}'

time:
  - platform: sntp
    on_time:
      - seconds: /15
        then:
          - logger.log:
              format: "Test String Value: ->%s<-"
              args: id(TestText).c_str()
          - logger.log:
              format: "Test 1, element 1: %s"
              args: 'id(TestArray)[0]'
          - logger.log:
              format: "Test 2, element 1: %s"
              args: id(TestArray)[0]
          - logger.log:
              format: "Test 3, element 1: %s"
              args: 'id(TestArray)[0].c_str()'
          - logger.log:
              format: "Test 4, element 1: %s"
              args: id(TestArray)[0].c_str()
          - logger.log:
              format: "Test 5, element 1: %s"
              args: (id(TestArray)[0]).c_str()
          # - logger.log:
          #     format: "Test 6, element 1: %s"
          #     args: id(TestArray[0]).c_str()
          # - logger.log:
          #     format: "Test 7, element 1: %s"
          #     args: 
          # - logger.log:
          #     format: "Test 8, element 1: %s"
          #     args: 
          # - logger.log:
          #     format: "Test 9, element 1: %s"
          #     args: 
          # - logger.log:
          #     format: "Test 10, element 1: %s"
          #     args: 
          # - logger.log:
          #     format: "Test 11, element 1: %s"
          #     args: 
          # - logger.log:
          #     format: "Test 12, element 1: %s"
          #     args: 
          - logger.log:
              format: "Divisor: 15 seconds, Current value, TestArray, First: %a, Dummy: %b, Second: %c, Third: %d, Fourth: %e, Fifth: %f"
              args: 
                - 'id(TestArray)[0]'
                - id(TestArray)[1]
                - 'id(TestArray)[2].c_str()'
                - id(TestArray)[3].c_str()
                - (id(TestArray)[0]).c_str()

(Since I’m testing just what format works, I have a lot of commented out lines for the different formats.)

I see two problems in here that, to me, appear to be bugs. I can’t explain them or see a reason for them, but I also know I still know very little about this. I’ll take the simpler issue first - it’s not the one that concerns me the most, but it’s easier to just get it out of the way.

In my last use of logger.log, I use format for the print string. Here’s the string, again, for convenience: Divisor: 15 seconds, Current value, TestArray, First: %a, Dummy: %b, Second: %c, Third: %d, Fourth: %e, Fifth: %f Note I have SIX places in there for inserting a variable for printing. But when I look at this in the ESPHome edit, it treats it as only FIVE printf patterns. It ignores %b, the 2nd one. I’ve used different letters, re-written the entire text to be printed, and played around with it. The bottom line is that the 2nd spot, the %b, is ignored. Here’s the output (this is the last line in the image), notice it prints a ‘b’ and ignores the percent sign:

I find this odd, since I copied one example into my YAML file in another section (that’s now commented out), and the editor and compiler didn’t have a problem with it:

#                 then:
#                   # - logger.log:
#                   #     format: 'Response status: %d, Duration: %u ms'
#                   #     args:
#                   #       - response->status_code
#                   #       - response->duration_ms

In this case, I never got errors. It saw 2 different places for inserting values. But I’ve tried a number of ways of rewriting my example and it still, always, treats that 2nd letter with the percent sign the same: It doesn’t see it my 2nd printf pattern.

What am I doing that the editor and compiler miss this as a printf pattern and why, if it doesn’t see it as one, does it still remove the percent sign?

Now, the major issue:
I would think, for the array, reading it so it could be put in a printf pattern, it would work the same as with the text variable. I use id(TestText).c_str() in the args statement and it works fine - see the first bright blue line in the output image for an example.

After that, I use five different formats to read the value of TestArray[0] and each one returns the string content of the first String element of that array. I don’t see why that’s happening. One of the five attempts to print the proper value in the log should work. The others should return gibberish or fail in some other way.

And it gets more confusing. Look at my last attempt to print Strings in the array. That’s the line with the %b that doesn’t seem to be seen as a printf pattern. It’s followed by 5 arg statements. I use the formatting I used above, where I tried printing out only one array member at a time. They all returned the value when I used only one at a time, but when I use five of them in that single line, I get gibberish. (I know - probably some pointers and other data, but it’s not the value of the elements of the array.)

So when I use one printf pattern per line of text, I’m getting the right value even with the wrong format, but when I use 5 printf patterns in one line, those same formats for the array element print junk.

  1. Why are all 5 attempts to print one element of the array working when some of the formats are clearly wrong? (The log lines starting with “Test 1” through “Test 5.”)
  2. Why do the formats for the value of one element of the array work when used one at a time, but they all fail when all used in one line?
  3. Why is the %b treated differently than the other printf patterns?
  4. What format should I be using if I want to print the value of an array element in a printf pattern? (My thought would be that it’d work like just printing a single string variable, but with an array index, so it’d be id(TestArray)[x].c_str().)