mirror of
https://github.com/esphome/esphome-docs.git
synced 2025-03-01 03:51:36 +01:00
Add logger.log action (#63)
This commit is contained in:
parent
facb424b08
commit
dbe519c87b
@ -74,6 +74,36 @@ purge all ``DEBUG`` log statements from the binary in order to conserve
|
||||
space. This however means that you cannot set tag-specific log levels
|
||||
that have a lower severity than the global log level.
|
||||
|
||||
.. _logger-log_action:
|
||||
|
||||
``logger.log`` Action
|
||||
---------------------
|
||||
|
||||
Print a formatted message to the logs.
|
||||
|
||||
In the ``format`` option, you can use ``printf``-style formatting (see :ref:`display-printf`).
|
||||
|
||||
.. code:: yaml
|
||||
|
||||
on_...:
|
||||
then:
|
||||
- logger.log: "Hello World"
|
||||
|
||||
# Formatted:
|
||||
- logger.log:
|
||||
format: "The temperature sensor reports value %.1f and humidity %.1f"
|
||||
args: [ 'id(temperature_sensor).value', 'id(humidity_sensor).value' ]
|
||||
|
||||
Configuration options:
|
||||
|
||||
- **format** (**Required**, string): The format for the message in :ref:`printf-style <display-printf>`.
|
||||
- **args** (*Optional*, list of :ref:`lambda <config-lambda>`): The optional arguments for the
|
||||
format message.
|
||||
- **level** (*Optional*, string): The :ref:`log level <logger-log_levels>` to print the message
|
||||
with. Defaults to ``DEBUG``.
|
||||
- **tag** (*Optional*, string): The tag (seen in front of the message in the logs) to print the message
|
||||
with. Defaults to ``main``.
|
||||
|
||||
See Also
|
||||
--------
|
||||
|
||||
|
@ -221,21 +221,6 @@ we're retrieving the current state of the end stop using ``.state`` and using it
|
||||
them into the generated C++ code. If compilation fails or something else is not working as expected
|
||||
with lambdas, it's always best to look at the generated C++ source file under ``<NODE_NAME>/src/main.cpp``.
|
||||
|
||||
.. tip::
|
||||
|
||||
An easy way to debug lambdas is to use esphomelib's logging engine:
|
||||
|
||||
.. code:: yaml
|
||||
|
||||
lambda: |-
|
||||
ESP_LOGE("main", "This is a red error message");
|
||||
ESP_LOGW("main", "This is a yellow warning message");
|
||||
ESP_LOGD("main", "This is a blue debug message");
|
||||
ESP_LOGV("main", "This is a gray verbose message"); // doesn't show up with the default log level.
|
||||
|
||||
// Use printf-style syntax (http://www.cplusplus.com/reference/cstdio/printf/)
|
||||
ESP_LOGD("main", "The temperature inside is %.1f", id(outside_temperature_sensor).state);
|
||||
|
||||
.. tip::
|
||||
|
||||
To store local variables inside lambdas that retain their value across executions, you can create ``static``
|
||||
@ -299,6 +284,7 @@ All Actions
|
||||
- :ref:`if <if_action>`
|
||||
- :ref:`component.update <component-update_action>`
|
||||
- :ref:`script.execute <script-execute_action>`
|
||||
- :ref:`logger.log <logger-log_action>`
|
||||
- :ref:`mqtt.publish <mqtt-publish_action>`
|
||||
- :ref:`mqtt.publish_json <mqtt-publish_json_action>`
|
||||
- :ref:`switch.toggle <switch-toggle_action>`
|
||||
|
Loading…
Reference in New Issue
Block a user