Log¶
API Reference¶
Header File¶
Functions¶
-
putchar_like_t
esp_log_set_putchar
(putchar_like_t func)¶ Set function used to output log entries.
By default, log output goes to UART0. This function can be used to redirect log output to some other destination, such as file or network. Returns the original log handler, which may be necessary to return output to the previous destination.
- Return
func old Function used for output.
- Parameters
func
: new Function used for output. Must have same signature as putchar.
-
uint32_t
esp_log_timestamp
(void)¶ Function which returns timestamp to be used in log output.
This function is used in expansion of ESP_LOGx macros. In the 2nd stage bootloader, and at early application startup stage this function uses CPU cycle counter as time source. Later when FreeRTOS scheduler start running, it switches to FreeRTOS tick count.
For now, we ignore millisecond counter overflow.
- Return
timestamp, in milliseconds
-
uint32_t
esp_log_early_timestamp
(void)¶ Function which returns timestamp to be used in log output.
This function uses HW cycle counter and does not depend on OS, so it can be safely used after application crash.
- Return
timestamp, in milliseconds
-
void
esp_log_write
(esp_log_level_t level, const char *tag, const char *format, ...)¶ Write message into the log.
This function is not intended to be used directly. Instead, use one of ESP_LOGE, ESP_LOGW, ESP_LOGI, ESP_LOGD, ESP_LOGV macros.
This function or these macros should not be used from an interrupt.
-
void
esp_early_log_write
(esp_log_level_t level, const char *tag, const char *format, ...)¶ Write message into the log at system startup or critical state.
This function is not intended to be used directly. Instead, use one of ESP_EARLY_LOGE, ESP_EARLY_LOGW, ESP_LEARLY_OGI, ESP_EARLY_LOGD, ESP_EARLY_LOGV macros.
This function or these macros can be used from an interrupt or NMI exception.
Macros¶
-
esp_log_level_set
(tag, level)¶
-
ESP_LOG_BUFFER_HEX_LEVEL
(tag, buffer, buff_len, level)¶ Log a buffer of hex bytes at specified level, separated into 16 bytes each line.
- Parameters
tag
: description tagbuffer
: Pointer to the buffer arraybuff_len
: length of buffer in byteslevel
: level of the log
-
ESP_LOG_BUFFER_CHAR_LEVEL
(tag, buffer, buff_len, level)¶ Log a buffer of characters at specified level, separated into 16 bytes each line. Buffer should contain only printable characters.
- Parameters
tag
: description tagbuffer
: Pointer to the buffer arraybuff_len
: length of buffer in byteslevel
: level of the log
-
ESP_LOG_BUFFER_HEXDUMP
(tag, buffer, buff_len, level)¶ Dump a buffer to the log at specified level.
The dump log shows just like the one below:
W (195) log_example: 0x3ffb4280 45 53 50 33 32 20 69 73 20 67 72 65 61 74 2c 20 |ESP32 is great, | W (195) log_example: 0x3ffb4290 77 6f 72 6b 69 6e 67 20 61 6c 6f 6e 67 20 77 69 |working along wi| W (205) log_example: 0x3ffb42a0 74 68 20 74 68 65 20 49 44 46 2e 00 |th the IDF..|
It is highly recommend to use terminals with over 102 text width.
- Parameters
tag
: description tagbuffer
: Pointer to the buffer arraybuff_len
: length of buffer in byteslevel
: level of the log
-
ESP_LOG_BUFFER_HEX
(tag, buffer, buff_len)¶ Log a buffer of hex bytes at Info level.
- See
esp_log_buffer_hex_level
- Parameters
tag
: description tagbuffer
: Pointer to the buffer arraybuff_len
: length of buffer in bytes
-
ESP_LOG_BUFFER_CHAR
(tag, buffer, buff_len)¶ Log a buffer of characters at Info level. Buffer should contain only printable characters.
- See
esp_log_buffer_char_level
- Parameters
tag
: description tagbuffer
: Pointer to the buffer arraybuff_len
: length of buffer in bytes
-
ESP_EARLY_LOGE
(tag, format, ...)¶ macro to output logs in startup code, before heap allocator and syscalls have been initialized. log at
ESP_LOG_ERROR
level.- See
printf
,ESP_LOGE
-
ESP_EARLY_LOGW
(tag, format, ...)¶ macro to output logs in startup code at
ESP_LOG_WARN
level.- See
ESP_EARLY_LOGE
,ESP_LOGE
,printf
-
ESP_EARLY_LOGI
(tag, format, ...)¶ macro to output logs in startup code at
ESP_LOG_INFO
level.- See
ESP_EARLY_LOGE
,ESP_LOGE
,printf
-
ESP_EARLY_LOGD
(tag, format, ...)¶ macro to output logs in startup code at
ESP_LOG_DEBUG
level.- See
ESP_EARLY_LOGE
,ESP_LOGE
,printf
-
ESP_EARLY_LOGV
(tag, format, ...)¶ macro to output logs in startup code at
ESP_LOG_VERBOSE
level.- See
ESP_EARLY_LOGE
,ESP_LOGE
,printf
-
ESP_LOG_EARLY_IMPL
(tag, format, log_level, log_tag_letter, ...)¶
-
ESP_LOGE
(tag, format, ...)¶
-
ESP_LOGW
(tag, format, ...)¶
-
ESP_LOGI
(tag, format, ...)¶
-
ESP_LOGD
(tag, format, ...)¶
-
ESP_LOGV
(tag, format, ...)¶
-
ESP_LOG_LEVEL
(level, tag, format, ...)¶ runtime macro to output logs at a specified level.
- See
printf
- Parameters
tag
: tag of the log, which can be used to change the log level byesp_log_level_set
at runtime.level
: level of the output log.format
: format of the output log. seeprintf
...
: variables to be replaced into the log. seeprintf
-
ESP_LOG_LEVEL_LOCAL
(level, tag, format, ...)¶ runtime macro to output logs at a specified level. Also check the level with
LOG_LOCAL_LEVEL
.- See
printf
,ESP_LOG_LEVEL
Type Definitions¶
-
typedef int (*
putchar_like_t
)(int ch)¶
Enumerations¶
-
enum
esp_log_level_t
¶ Log level.
Values:
-
ESP_LOG_NONE
= 0¶ No log output
-
ESP_LOG_ERROR
¶ Critical errors, software module can not recover on its own
-
ESP_LOG_WARN
¶ Error conditions from which recovery measures have been taken
-
ESP_LOG_INFO
¶ Information messages which describe normal flow of events
-
ESP_LOG_DEBUG
¶ Extra information which is not necessary for normal use (values, pointers, sizes, etc).
-
ESP_LOG_VERBOSE
¶ Bigger chunks of debugging information, or frequent messages which can potentially flood the output.
-
ESP_LOG_MAX
¶
-