README.rst 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. Logging library
  2. ===============
  3. Overview
  4. --------
  5. Log library has two ways of managing log verbosity: compile time, set via menuconfig; and runtime, using :cpp:func:`esp_log_level_set` function.
  6. The log levels are Error, Warning, Info, Debug, and Verbose (from lowest to highest level of verbosity).
  7. 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.
  8. 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.
  9. 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).
  10. How to use this library
  11. -----------------------
  12. In each C file which uses logging functionality, define TAG variable like this:
  13. .. code-block:: c
  14. static const char* TAG = "MyModule";
  15. then use one of logging macros to produce output, e.g:
  16. .. code-block:: c
  17. ESP_LOGW(TAG, "Baud rate error %.1f%%. Requested: %d baud, actual: %d baud", error * 100, baud_req, baud_real);
  18. Several macros are available for different verbosity levels:
  19. * ``ESP_LOGE`` - error (lowest)
  20. * ``ESP_LOGW`` - warning
  21. * ``ESP_LOGI`` - info
  22. * ``ESP_LOGD`` - debug
  23. * ``ESP_LOGV`` - verbose (highest)
  24. 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.
  25. 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.:
  26. .. code-block:: c
  27. #define LOG_LOCAL_LEVEL ESP_LOG_VERBOSE
  28. #include "esp_log.h"
  29. At component scope, define it in component makefile:
  30. .. code-block:: make
  31. CFLAGS += -D LOG_LOCAL_LEVEL=ESP_LOG_DEBUG
  32. To configure logging output per module at runtime, add calls to :cpp:func:`esp_log_level_set` function:
  33. .. code-block:: c
  34. esp_log_level_set("*", ESP_LOG_ERROR); // set all components to ERROR level
  35. esp_log_level_set("wifi", ESP_LOG_WARN); // enable WARN logs from WiFi stack
  36. esp_log_level_set("dhcpc", ESP_LOG_INFO); // enable INFO logs from DHCP client
  37. Logging to Host via JTAG
  38. ^^^^^^^^^^^^^^^^^^^^^^^^
  39. 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`.