Help with esphome logger automation please

Please help. I can’t understand what I am doing wrong.
I have idea to send esphome log output back to home assistant via text sensor.

For that, I defined text sensor

text_sensor:
  - platform: template
    name: "${friendly_name} Log output"
    id: log_output

And for logger component I defined on_message automation:

logger:
  level: INFO
  id: mylogger
  on_message:
    level: ERROR
    then:
      - text_sensor.template.publish:
          id: log_output
          state: !lambda 'return "Triggered on_message with level " + std::to_string(level) + ", tag " + tag + " and message " + message;'
  logs:
    i2c: ERROR

Basically, I combined example for template text sensor and logger automation.

Unfortunatelly, it won’t compile. Compiler don’t recognize std::to_string(level), tag and message, despite this literaly taken from manual.
I can return any kind of fixed string, for example state: !lambda 'return “Hello world”;, but no message from logger.
Complete compiler output is below.

INFO Reading configuration tagreader_keypadtext.yaml...
INFO Generating C++ source...
INFO Compiling app...
INFO Running:  platformio run -d tagreader
Processing tagreader (board: esp32doit-devkit-v1; framework: arduino; platform: https://github.com/platformio/platform-espressif32.git)
-----------------------------------------------------------------------------------------------
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
PACKAGES: 
 - framework-arduinoespressif32 3.10006.210326 (1.0.6) 
 - tool-esptoolpy 1.30000.201119 (3.0.0) 
 - toolchain-xtensa32 2.50200.97 (5.2.0)
Library Manager: Installing Hash
Library Manager: Already installed, built-in library
Dependency Graph
|-- <AsyncTCP-esphome> 1.1.1
|-- <ESPmDNS> 1.0
|   |-- <WiFi> 1.0
|-- <Keypad> 3.1.1
|-- <FS> 1.0
|-- <ESPAsyncWebServer-esphome> 1.2.7
|   |-- <AsyncTCP-esphome> 1.1.1
|   |-- <FS> 1.0
|   |-- <WiFi> 1.0
|-- <Wire> 1.0.1
|-- <FastLED> 3.3.2
|   |-- <SPI> 1.0
|-- <DNSServer> 1.1.0
|   |-- <WiFi> 1.0
|-- <Update> 1.0
|-- <WiFi> 1.0
Compiling .pioenvs/tagreader/src/esphome/components/template/text_sensor/template_text_sensor.cpp.o
Compiling .pioenvs/tagreader/src/main.cpp.o
src/main.cpp: In lambda function:
src/main.cpp:1341:51: error: 'to_string' is not a member of 'std'
       return "Triggered on_message with level " + std::to_string(level) + ", tag " + tag + " and message " + message;
                                                   ^
src/main.cpp:1341:51: note: suggested alternatives:
In file included from src/esphome/core/application.h:8:0,
                 from src/esphome/components/api/api_connection.h:4,
                 from src/esphome.h:2,
                 from src/main.cpp:3:
src/esphome/core/helpers.h:43:13: note:   'esphome::to_string'
 std::string to_string(long double val);
             ^
src/esphome/core/helpers.h:43:13: note:   'esphome::to_string'
*** [.pioenvs/tagreader/src/main.cpp.o] Error 1

Btw. when I remove std::to_string(level) it wont compile either, compiler dont recognize tag and message variables.

The example uses " whereas you use '.

???
I really don’t understand you.