• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..--

include/11-Mar-2024-416158

CMakeLists.txtD11-Mar-2024583 1613

KconfigD11-Mar-20242.6 KiB7461

README.rstD11-Mar-20243.1 KiB7846

component.mkD11-Mar-2024402 156

esp_log_private.hD11-Mar-2024135 75

linker.lfD11-Mar-2024314 109

log.cD11-Mar-20249.5 KiB298205

log_buffers.cD11-Mar-20244.7 KiB148114

log_freertos.cD11-Mar-20243.5 KiB11786

log_noos.cD11-Mar-20241.5 KiB6338

README.rst

1Logging library
2===============
3
4Overview
5--------
6
7The logging library provides two ways for setting log verbosity:
8
9- **At compile time**: in menuconfig, set the verbosity level using the option :envvar:`CONFIG_LOG_DEFAULT_LEVEL`. All logging statements for verbosity levels higher than :envvar:`CONFIG_LOG_DEFAULT_LEVEL` will be removed by the preprocessor.
10- **At runtime**: all logs for verbosity levels lower than :envvar:`CONFIG_LOG_DEFAULT_LEVEL` are enabled by default. The function :cpp:func:`esp_log_level_set` can be used to set a logging level on a per module basis. Modules are identified by their tags, which are human-readable ASCII zero-terminated strings.
11
12There are the following verbosity levels:
13
14- Error (lowest)
15- Warning
16- Info
17- Debug
18- Verbose (highest)
19
20.. note::
21
22    The function :cpp:func:`esp_log_level_set` cannot set logging levels higher than specified by :envvar:`CONFIG_LOG_DEFAULT_LEVEL`. To increase log level for a specific file at compile time, use the macro `LOG_LOCAL_LEVEL` (see the details below).
23
24
25How to use this library
26-----------------------
27
28In each C file that uses logging functionality, define the TAG variable as shown below:
29
30.. code-block:: c
31
32   static const char* TAG = "MyModule";
33
34Then use one of logging macros to produce output, e.g:
35
36.. code-block:: c
37
38   ESP_LOGW(TAG, "Baud rate error %.1f%%. Requested: %d baud, actual: %d baud", error * 100, baud_req, baud_real);
39
40Several macros are available for different verbosity levels:
41
42* ``ESP_LOGE`` - error (lowest)
43* ``ESP_LOGW`` - warning
44* ``ESP_LOGI`` - info
45* ``ESP_LOGD`` - debug
46* ``ESP_LOGV`` - verbose (highest)
47
48Additionally, there are ``ESP_EARLY_LOGx`` versions for each of these macros, e.g., :c:macro:`ESP_EARLY_LOGE`. These versions have to be used explicitly in the early startup code only, before heap allocator and syscalls have been initialized. Normal ``ESP_LOGx`` macros can also be used while compiling the bootloader, but they will fall back to the same implementation as ``ESP_EARLY_LOGx`` macros.
49
50To override default verbosity level at file or component scope, define the ``LOG_LOCAL_LEVEL`` macro.
51
52At file scope, define it before including ``esp_log.h``, e.g.:
53
54.. code-block:: c
55
56   #define LOG_LOCAL_LEVEL ESP_LOG_VERBOSE
57   #include "esp_log.h"
58
59At component scope, define it in the component makefile:
60
61.. code-block:: make
62
63   CFLAGS += -D LOG_LOCAL_LEVEL=ESP_LOG_DEBUG
64
65To configure logging output per module at runtime, add calls to the function :cpp:func:`esp_log_level_set` as follows:
66
67.. code-block:: c
68
69   esp_log_level_set("*", ESP_LOG_ERROR);        // set all components to ERROR level
70   esp_log_level_set("wifi", ESP_LOG_WARN);      // enable WARN logs from WiFi stack
71   esp_log_level_set("dhcpc", ESP_LOG_INFO);     // enable INFO logs from DHCP client
72
73Logging to Host via JTAG
74^^^^^^^^^^^^^^^^^^^^^^^^
75
76By default, the logging library uses the vprintf-like function to write formatted output to the dedicated UART. By calling a simple API, all log output may be routed to JTAG instead, making logging several times faster. For details, please refer to Section :ref:`app_trace-logging-to-host`.
77
78