7 Log library has two ways of managing log verbosity: compile time, set via menuconfig; and runtime, using :cpp:func:`esp_log_level_set` function.
9 The log levels are Error, Warning, Info, Debug, and Verbose (from lowest to highest level of verbosity).
11 At compile time, filtering is done using :envvar:`CONFIG_LOG_DEFAULT_LEVEL` option, set via menuconfig. All logging statements for levels higher than :envvar:`CONFIG_LOG_DEFAULT_LEVEL` will be removed by the preprocessor.
13 At run time, all logs below :envvar:`CONFIG_LOG_DEFAULT_LEVEL` are enabled by default. :cpp:func:`esp_log_level_set` function may be used to reduce logging level per module. Modules are identified by their tags, which are human-readable ASCII zero-terminated strings.
15 Note that :cpp:func:`esp_log_level_set` can not increase logging level beyound that set by :envvar:`CONFIG_LOG_DEFAULT_LEVEL`. To increase log level for a specific file at compile time, `LOG_LOCAL_LEVEL` macro can be used (see below for details).
17 How to use this library
18 -----------------------
20 In each C file which uses logging functionality, define TAG variable like this:
24 static const char* TAG = "MyModule";
26 then use one of logging macros to produce output, e.g:
30 ESP_LOGW(TAG, "Baud rate error %.1f%%. Requested: %d baud, actual: %d baud", error * 100, baud_req, baud_real);
32 Several macros are available for different verbosity levels:
34 * ``ESP_LOGE`` - error (lowest)
35 * ``ESP_LOGW`` - warning
37 * ``ESP_LOGD`` - debug
38 * ``ESP_LOGV`` - verbose (highest)
40 Additionally there is an ``_EARLY`` variant for each of these macros (e.g. :c:macro:`ESP_EARLY_LOGE`). These variants can run in startup code, before heap allocator and syscalls have been initialized. When compiling bootloader, normal ``ESP_LOGx`` macros fall back to the same implementation as ``ESP_EARLY_LOGx`` macros. So the only place where ``ESP_EARLY_LOGx`` have to be used explicitly is the early startup code, such as heap allocator initialization code.
42 To override default verbosity level at file or component scope, define ``LOG_LOCAL_LEVEL`` macro. At file scope, define it before including ``esp_log.h``, e.g.:
46 #define LOG_LOCAL_LEVEL ESP_LOG_VERBOSE
50 At component scope, define it in component makefile:
54 CFLAGS += -D LOG_LOCAL_LEVEL=ESP_LOG_DEBUG
56 To configure logging output per module at runtime, add calls to :cpp:func:`esp_log_level_set` function:
60 esp_log_level_set("*", ESP_LOG_ERROR); // set all components to ERROR level
61 esp_log_level_set("wifi", ESP_LOG_WARN); // enable WARN logs from WiFi stack
62 esp_log_level_set("dhcpc", ESP_LOG_INFO); // enable INFO logs from DHCP client
64 Logging to Host via JTAG
65 ^^^^^^^^^^^^^^^^^^^^^^^^
67 By default logging library uses vprintf-like function to write formatted output to 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`.