esp_log.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2022 Gunar Schorcht
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
20 #ifndef LOG_ESP_LOG_H
21 #define LOG_ESP_LOG_H
22 
23 #ifndef DOXYGEN /* Hide implementation details from doxygen */
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 #include_next "esp_log.h"
30 
31 #if defined(RIOT_VERSION)
32 
33 #include "esp_common.h"
34 
35 #ifndef LOG_LOCAL_LEVEL
36 #define LOG_LOCAL_LEVEL LOG_LEVEL
37 #endif
38 
39 #define ESP_LOG_LEVEL(level, tag, format, ...) \
40  do { \
41  if ((esp_log_level_t)level==ESP_LOG_ERROR ) { \
42  ESP_LOGE(tag, format, ##__VA_ARGS__); \
43  } \
44  else if ((esp_log_level_t)level==ESP_LOG_WARN ) { \
45  ESP_LOGW(tag, format, ##__VA_ARGS__); \
46  } \
47  else if ((esp_log_level_t)level==ESP_LOG_INFO ) { \
48  ESP_LOGI(tag, format, ##__VA_ARGS__); \
49  } \
50  else if ((esp_log_level_t)level==ESP_LOG_DEBUG ) { \
51  ESP_LOGD(tag, format, ##__VA_ARGS__); \
52  } \
53  else if ((esp_log_level_t)level==ESP_LOG_VERBOSE ) { \
54  ESP_LOGV(tag, format, ##__VA_ARGS__); \
55  } \
56  } while (0)
57 
58 #define ESP_LOG_LEVEL_LOCAL(level, tag, format, ...) \
59  do { \
60  if ( LOG_LOCAL_LEVEL >= level ) { \
61  ESP_LOG_LEVEL(level, tag, format, ##__VA_ARGS__); \
62  } \
63  } while (0)
64 
65 #define ESP_LOGE(tag, format, ...) esp_log_write((esp_log_level_t)LOG_ERROR , tag, format "\n", ##__VA_ARGS__)
66 #define ESP_LOGW(tag, format, ...) esp_log_write((esp_log_level_t)LOG_WARNING, tag, format "\n", ##__VA_ARGS__)
67 #define ESP_LOGI(tag, format, ...) esp_log_write((esp_log_level_t)LOG_INFO , tag, format "\n", ##__VA_ARGS__)
68 #define ESP_LOGD(tag, format, ...) esp_log_write((esp_log_level_t)LOG_DEBUG , tag, format "\n", ##__VA_ARGS__)
69 #define ESP_LOGV(tag, format, ...) esp_log_write((esp_log_level_t)LOG_ALL , tag, format "\n", ##__VA_ARGS__)
70 
71 #if MODULE_ESP_LOG_TAGGED
72 
73 #define ESP_DRAM_LOGE(tag, format, ...) \
74  do { \
75  if ((esp_log_level_t)LOG_LOCAL_LEVEL >= ESP_LOG_ERROR ) { \
76  esp_rom_printf(DRAM_STR(LOG_FORMAT(E, format)), \
77  system_get_time_ms(), ##__VA_ARGS__); \
78  }\
79  } while (0U)
80 
81 #else
82 
83 #define ESP_DRAM_LOGE(tag, format, ...) \
84  do { \
85  if ((esp_log_level_t)LOG_LOCAL_LEVEL >= ESP_LOG_ERROR ) { \
86  esp_rom_printf(DRAM_STR(LOG_FORMAT(E, format)), \
87  ##__VA_ARGS__); \
88  }\
89  } while (0U)
90 
91 #endif
92 
93 
94 #endif /* defined(RIOT_VERSION) */
95 
96 #ifdef __cplusplus
97 }
98 #endif
99 
100 #endif /* DOXYGEN */
101 #endif /* LOG_ESP_LOG_H */
Common helper macros for ESP SoCs.