Skip to content

Commit

Permalink
Merge branch 'fix/monitor_print_filter_v5.2' into 'release/v5.2'
Browse files Browse the repository at this point in the history
fix(tools/monitor): fix PRINT_FILTER env variable usage (v5.2)

See merge request espressif/esp-idf!27417
  • Loading branch information
dobairoland committed Nov 30, 2023
2 parents 587b4b3 + 63ea519 commit 026fb6e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
16 changes: 10 additions & 6 deletions docs/en/api-guides/tools/idf-monitor.rst
Original file line number Diff line number Diff line change
Expand Up @@ -256,15 +256,19 @@ In both cases (i.e., sending the ``Ctrl+C`` message, or receiving the special st
Output Filtering
~~~~~~~~~~~~~~~~

IDF monitor can be invoked as ``idf.py monitor --print-filter="xyz"``, where ``--print-filter`` is the parameter for output filtering. The default value is an empty string, which means that everything is printed.
IDF monitor can be invoked as ``idf.py monitor --print-filter="xyz"``, where ``--print-filter`` is the parameter for output filtering. The default value is an empty string, which means that everything is printed. Filtering can also be configured using the ``ESP_IDF_MONITOR_PRINT_FILTER`` environment variable.

.. note::

When using both the environment variable ``ESP_IDF_MONITOR_PRINT_FILTER`` and the argument ``--print-filter``, the setting from the CLI argument will take precedence.

Restrictions on what to print can be specified as a series of ``<tag>:<log_level>`` items where ``<tag>`` is the tag string and ``<log_level>`` is a character from the set ``{N, E, W, I, D, V, *}`` referring to a level for :doc:`logging <../../api-reference/system/log>`.

For example, ``PRINT_FILTER="tag1:W"`` matches and prints only the outputs written with ``ESP_LOGW("tag1", ...)`` or at lower verbosity level, i.e., ``ESP_LOGE("tag1", ...)``. Not specifying a ``<log_level>`` or using ``*`` defaults to Verbose level.
For example, ``--print_filter="tag1:W"`` matches and prints only the outputs written with ``ESP_LOGW("tag1", ...)`` or at lower verbosity level, i.e., ``ESP_LOGE("tag1", ...)``. Not specifying a ``<log_level>`` or using ``*`` defaults to a Verbose level.

.. note::

Use primary logging to disable at compilation the outputs you do not need through the :doc:`logging library <../../api-reference/system/log>`. Output filtering with ESP- monitor is a secondary solution which can be useful for adjusting the filtering options without recompiling the application.
Use primary logging to disable at compilation the outputs you do not need through the :doc:`logging library <../../api-reference/system/log>`. Output filtering with the IDF monitor is a secondary solution that can be useful for adjusting the filtering options without recompiling the application.

Your app tags must not contain spaces, asterisks ``*``, or colons ``:`` to be compatible with the output filtering feature.

Expand All @@ -273,7 +277,7 @@ If the last line of the output in your app is not followed by a carriage return,
Examples of Filtering Rules:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

- ``*`` can be used to match any tags. However, the string ``PRINT_FILTER="*:I tag1:E"`` with regards to ``tag1`` prints errors only, because the rule for ``tag1`` has a higher priority over the rule for ``*``.
- ``*`` can be used to match any tags. However, the string ``--print_filter="*:I tag1:E"`` with regards to ``tag1`` prints errors only, because the rule for ``tag1`` has a higher priority over the rule for ``*``.
- The default (empty) rule is equivalent to ``*:V`` because matching every tag at the Verbose level or lower means matching everything.
- ``"*:N"`` suppresses not only the outputs from logging functions, but also the prints made by ``printf``, etc. To avoid this, use ``*:E`` or a higher verbosity level.
- Rules ``"tag1:V"``, ``"tag1:v"``, ``"tag1:"``, ``"tag1:*"``, and ``"tag1"`` are equivalent.
Expand All @@ -300,12 +304,12 @@ The following log snippet was acquired without any filtering options::
D (318) vfs: esp_vfs_register_fd_range is successful for range <54; 64) and VFS ID 1
I (328) wifi: wifi driver task: 3ffdbf84, prio:23, stack:4096, core=0

The captured output for the filtering options ``PRINT_FILTER="wifi esp_image:E light_driver:I"`` is given below::
The captured output for the filtering options ``--print_filter="wifi esp_image:E light_driver:I"`` is given below::

E (31) esp_image: image at 0x30000 has invalid magic byte
I (328) wifi: wifi driver task: 3ffdbf84, prio:23, stack:4096, core=0

The options ``PRINT_FILTER="light_driver:D esp_image:N boot:N cpu_start:N vfs:N wifi:N *:V"`` show the following output::
The options ``--print_filter="light_driver:D esp_image:N boot:N cpu_start:N vfs:N wifi:N *:V"`` show the following output::

load:0x40078000,len:13564
entry 0x40078d4c
Expand Down
14 changes: 9 additions & 5 deletions docs/zh_CN/api-guides/tools/idf-monitor.rst
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,15 @@ GDBStub 支持在运行时进行调试。GDBStub 在目标上运行,并通过
输出筛选
~~~~~~~~~~~~~~~~

可以调用 ``idf.py monitor --print-filter="xyz"`` 启动 IDF 监视器,其中,``--print-filter`` 是输出筛选的参数。参数默认值为空字符串,可打印任何内容。
可以调用 ``idf.py monitor --print-filter="xyz"`` 启动 IDF 监视器,其中,``--print-filter`` 是输出筛选的参数。参数默认值为空字符串,即打印所有内容。支持使用环境变量 ``ESP_IDF_MONITOR_PRINT_FILTER`` 调整筛选设置。

.. note::

同时使用环境变量 ``ESP_IDF_MONITOR_PRINT_FILTER`` 和参数 ``--print-filter`` 时,通过命令行输入的 CLI 参数 ``--print-filter`` 优先级更高。

若需对打印内容设置限制,可指定 ``<tag>:<log_level>`` 等选项,其中 ``<tag>`` 是标签字符串,``<log_level>`` 是 ``{N, E, W, I, D, V, *}`` 集合中的一个字母,指的是 :doc:`日志 <../../api-reference/system/log>` 级别。

例如,``PRINT_FILTER="tag1:W"`` 只匹配并打印 ``ESP_LOGW("tag1", ...)`` 所写的输出,或者写在较低日志详细度级别的输出,即 ``ESP_LOGE("tag1", ...)``。请勿指定 ``<log_level>`` 或使用详细级别默认值 ``*``。
例如,``--print_filter="tag1:W"`` 只匹配并打印 ``ESP_LOGW("tag1", ...)`` 所写的输出,或者写在较低日志详细度级别的输出,即 ``ESP_LOGE("tag1", ...)``。请勿指定 ``<log_level>`` 或使用详细级别默认值 ``*``。

.. note::

Expand All @@ -273,7 +277,7 @@ GDBStub 支持在运行时进行调试。GDBStub 在目标上运行,并通过
筛选规则示例
~~~~~~~~~~~~~~~~

- ``*`` 可用于匹配任何类型标签。但 ``PRINT_FILTER="*:I tag1:E"`` 打印关于 ``tag1`` 的输出时会报错,这是因为 ``tag1`` 规则比 ``*`` 规则的优先级高。
- ``*`` 可用于匹配任何类型标签。但 ``--print_filter="*:I tag1:E"`` 打印关于 ``tag1`` 的输出时会报错,这是因为 ``tag1`` 规则比 ``*`` 规则的优先级高。
- 默认规则(空)等价于 ``*:V``,因为在详细级别或更低级别匹配任意标签即意味匹配所有内容。
- ``"*:N"`` 不仅抑制了日志功能的输出,也抑制了 ``printf`` 的打印输出。为了避免这一问题,请使用 ``*:E`` 或更高的冗余级别。
- 规则 ``"tag1:V"``、``"tag1:v"``、``"tag1:"``、``"tag1:*"`` 和 ``"tag1"`` 等同。
Expand All @@ -300,12 +304,12 @@ GDBStub 支持在运行时进行调试。GDBStub 在目标上运行,并通过
D (318) vfs: esp_vfs_register_fd_range is successful for range <54; 64) and VFS ID 1
I (328) wifi: wifi driver task: 3ffdbf84, prio:23, stack:4096, core=0

``PRINT_FILTER="wifi esp_image:E light_driver:I"`` 筛选选项捕获的输出如下所示::
``--print_filter="wifi esp_image:E light_driver:I"`` 筛选选项捕获的输出如下所示::

E (31) esp_image: image at 0x30000 has invalid magic byte
I (328) wifi: wifi driver task: 3ffdbf84, prio:23, stack:4096, core=0

``PRINT_FILTER="light_driver:D esp_image:N boot:N cpu_start:N vfs:N wifi:N *:V"`` 选项的输出如下::
``--print_filter="light_driver:D esp_image:N boot:N cpu_start:N vfs:N wifi:N *:V"`` 选项的输出如下::

load:0x40078000,len:13564
entry 0x40078d4c
Expand Down

0 comments on commit 026fb6e

Please sign in to comment.