Add logger.log action (#63)

This commit is contained in:
Otto Winter 2018-10-20 15:19:31 +02:00 committed by GitHub
parent facb424b08
commit dbe519c87b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 15 deletions

View File

@ -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
--------

View File

@ -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>`