esp_log.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #ifndef __ESP_LOG_H__
  14. #define __ESP_LOG_H__
  15. #include <stdint.h>
  16. #include <stdarg.h>
  17. #include "esp_common.h"
  18. //#include "ets_sys.h"
  19. #define CONFIG_LOG_COLORS 1
  20. #define CONFIG_LOG_DEFAULT_LEVEL 100
  21. #define CPU_CLK_FREQ 80000000
  22. /**
  23. * @brief Log level
  24. *
  25. */
  26. typedef enum {
  27. ESP_LOG_NONE, /*!< No log output */
  28. ESP_LOG_ERROR, /*!< Critical errors, software module can not recover on its own */
  29. ESP_LOG_WARN, /*!< Error conditions from which recovery measures have been taken */
  30. ESP_LOG_INFO, /*!< Information messages which describe normal flow of events */
  31. ESP_LOG_DEBUG, /*!< Extra information which is not necessary for normal use (values, pointers, sizes, etc). */
  32. ESP_LOG_VERBOSE /*!< Bigger chunks of debugging information, or frequent messages which can potentially flood the output. */
  33. } esp_log_level_t;
  34. /**
  35. * @brief Function which returns timestamp to be used in log output
  36. *
  37. * This function is used in expansion of ESP_LOGx macros.
  38. * In the 2nd stage bootloader, and at early application startup stage
  39. * this function uses CPU cycle counter as time source. Later when
  40. * FreeRTOS scheduler start running, it switches to FreeRTOS tick count.
  41. *
  42. * For now, we ignore millisecond counter overflow.
  43. *
  44. * @return timestamp, in milliseconds
  45. */
  46. uint32_t esp_log_timestamp(void);
  47. #if CONFIG_LOG_COLORS
  48. #define LOG_COLOR_BLACK "30"
  49. #define LOG_COLOR_RED "31"
  50. #define LOG_COLOR_GREEN "32"
  51. #define LOG_COLOR_BROWN "33"
  52. #define LOG_COLOR_BLUE "34"
  53. #define LOG_COLOR_PURPLE "35"
  54. #define LOG_COLOR_CYAN "36"
  55. #define LOG_COLOR(COLOR) "\033[0;" COLOR "m"
  56. #define LOG_BOLD(COLOR) "\033[1;" COLOR "m"
  57. #define LOG_RESET_COLOR "\033[0m"
  58. #define LOG_COLOR_E LOG_COLOR(LOG_COLOR_RED)
  59. #define LOG_COLOR_W LOG_COLOR(LOG_COLOR_BROWN)
  60. #define LOG_COLOR_I LOG_COLOR(LOG_COLOR_GREEN)
  61. #define LOG_COLOR_D
  62. #define LOG_COLOR_V
  63. #else //CONFIG_LOG_COLORS
  64. #define LOG_COLOR_E
  65. #define LOG_COLOR_W
  66. #define LOG_COLOR_I
  67. #define LOG_COLOR_D
  68. #define LOG_COLOR_V
  69. #define LOG_RESET_COLOR
  70. #endif //CONFIG_LOG_COLORS
  71. #define LOG_FORMAT(letter, format) LOG_COLOR_ ## letter #letter " (%u) %s: " format LOG_RESET_COLOR "\n"
  72. #define LOG_LOCAL_LEVEL ((esp_log_level_t) CONFIG_LOG_DEFAULT_LEVEL)
  73. #define ESP_LOGE( tag, format, ... ) if (LOG_LOCAL_LEVEL >= ESP_LOG_ERROR) { os_printf(LOG_FORMAT(E, format), esp_log_timestamp(), tag, ##__VA_ARGS__); }
  74. #define ESP_LOGW( tag, format, ... ) if (LOG_LOCAL_LEVEL >= ESP_LOG_WARN) { os_printf(LOG_FORMAT(W, format), esp_log_timestamp(), tag, ##__VA_ARGS__); }
  75. #define ESP_LOGI( tag, format, ... ) if (LOG_LOCAL_LEVEL >= ESP_LOG_INFO) { os_printf(LOG_FORMAT(I, format), esp_log_timestamp(), tag, ##__VA_ARGS__); }
  76. #define ESP_LOGD( tag, format, ... ) if (LOG_LOCAL_LEVEL >= ESP_LOG_DEBUG) { os_printf(LOG_FORMAT(D, format), esp_log_timestamp(), tag, ##__VA_ARGS__); }
  77. #define ESP_LOGV( tag, format, ... ) if (LOG_LOCAL_LEVEL >= ESP_LOG_VERBOSE) { os_printf(LOG_FORMAT(V, format), esp_log_timestamp(), tag, ##__VA_ARGS__); }
  78. #endif /* __ESP_LOG_H__ */