esp_log_level.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #pragma once
  7. #include <stdbool.h>
  8. #include "esp_log.h"
  9. #ifdef __cplusplus
  10. extern "C" {
  11. #endif
  12. __attribute__((always_inline))
  13. static inline esp_log_level_t esp_log_get_default_level(void)
  14. {
  15. return (esp_log_level_t) CONFIG_LOG_DEFAULT_LEVEL;
  16. }
  17. /**
  18. * @brief Set the default log level.
  19. *
  20. * This function sets the default log level used by the ESP-IDF log library.
  21. * The default log level is used by the definition of ESP_LOGx macros and
  22. * can be overridden for specific tags using `esp_log_level_set("*", level)`.
  23. * This is for internal use only.
  24. *
  25. * If CONFIG_LOG_DYNAMIC_LEVEL_CONTROL is not set, this function does not change the default log level.
  26. *
  27. * @param level The new default log level to set.
  28. */
  29. void esp_log_set_default_level(esp_log_level_t level);
  30. /**
  31. * @brief Set log level for given tag
  32. *
  33. * If logging for given component has already been enabled, changes previous setting.
  34. *
  35. * @note Note that this function can not raise log level above the level set using
  36. * CONFIG_LOG_MAXIMUM_LEVEL setting in menuconfig.
  37. *
  38. * To raise log level above the default one for a given file, define
  39. * LOG_LOCAL_LEVEL to one of the ESP_LOG_* values, before including esp_log.h in this file.
  40. *
  41. * If CONFIG_LOG_DYNAMIC_LEVEL_CONTROL is not selected the static (no-op) implementation of log level is used.
  42. * Changing the log level is not possible, esp_log_level_set does not work.
  43. *
  44. * @param tag Tag of the log entries to enable. Must be a non-NULL zero terminated string.
  45. * Value "*" resets log level for all tags to the given value.
  46. * If the tag is NULL then a silent return happens.
  47. * @param level Selects log level to enable.
  48. * Only logs at this and lower verbosity levels will be shown.
  49. */
  50. void esp_log_level_set(const char* tag, esp_log_level_t level);
  51. /**
  52. * @brief Get log level for a given tag, can be used to avoid expensive log statements
  53. *
  54. * If CONFIG_LOG_DYNAMIC_LEVEL_CONTROL is not selected the static (no-op) implementation of log level is used.
  55. * Changing the log level is not possible, esp_log_level_set does not work. This function returns the default log level.
  56. *
  57. * @param tag Tag of the log to query current level. Must be a zero terminated string.
  58. * If tag is NULL then the default log level is returned (see esp_log_get_default_level()).
  59. * @return The current log level for the given tag.
  60. */
  61. esp_log_level_t esp_log_level_get(const char* tag);
  62. #ifdef __cplusplus
  63. }
  64. #endif