Loading...
Searching...
No Matches
esp_common_log.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2019 Gunar Schorcht
3 * SPDX-License-Identifier: LGPL-2.1-only
4 */
5
6#pragma once
7
18
19#ifndef DOXYGEN
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
25#include <stdio.h>
26#include <stdint.h>
27#include <inttypes.h>
28
29#include "log.h"
30
31extern uint32_t system_get_time_ms (void);
32extern int ets_printf(const char *fmt, ...);
33
34#if MODULE_ESP_LOG_COLORED
35
36#define LOG_RESET_COLOR "\033[0m"
37#define LOG_COLOR_E "\033[1;31m"
38#define LOG_COLOR_W "\033[1;33m"
39#define LOG_COLOR_I "\033[1m"
40#define LOG_COLOR_D "\033[0;32m"
41#define LOG_COLOR_V
42
43#else /* MODULE_ESP_LOG_COLORED */
44
45#define LOG_RESET_COLOR
46#define LOG_COLOR_E
47#define LOG_COLOR_W
48#define LOG_COLOR_I
49#define LOG_COLOR_D
50#define LOG_COLOR_V
51
52#endif /* MODULE_ESP_LOG_COLORED */
53
54#if MODULE_ESP_LOG_TAGGED
55
56#define LOG_FORMAT(letter, format) LOG_COLOR_ ## letter #letter " (%" PRIu32 ") [%s] " format LOG_RESET_COLOR
57
58#define LOG_TAG(level, letter, tag, format, ...) \
59 do { \
60 if ((unsigned)level <= (unsigned)LOG_LEVEL) { \
61 printf(LOG_FORMAT(letter, format), system_get_time_ms(), tag, ##__VA_ARGS__); \
62 fflush(stdout); \
63 } \
64 } while (0)
65
66#define LOG_TAG_EARLY(level, letter, tag, format, ...) \
67 do { \
68 if (LOG_LEVEL >= level) { \
69 ets_printf(LOG_FORMAT(letter, format), system_get_time_ms(), tag, ##__VA_ARGS__); \
70 } \
71 } while (0)
72
73#else /* MODULE_ESP_LOG_TAGGED */
74
75#define LOG_FORMAT(letter, format) LOG_COLOR_ ## letter format LOG_RESET_COLOR
76
77#define LOG_TAG(level, letter, tag, format, ...) \
78 do { \
79 (void)tag; \
80 if ((unsigned)level <= (unsigned)LOG_LEVEL) { \
81 printf(LOG_FORMAT(letter, format), ##__VA_ARGS__); \
82 fflush(stdout); \
83 } \
84 } while (0U)
85
86#define LOG_TAG_EARLY(level, letter, tag, format, ...) \
87 do { \
88 (void)tag; \
89 if ((unsigned)level <= (unsigned)LOG_LEVEL) { \
90 ets_printf(LOG_FORMAT(letter, format), ##__VA_ARGS__); \
91 } \
92 } while (0U)
93
94#endif /* MODULE_ESP_LOG_TAGGED */
95
100#ifndef MODULE_LOG_PRINTFNOFORMAT
101#undef LOG_ERROR
102#undef LOG_INFO
103#undef LOG_WARNING
104#undef LOG_DEBUG
105#define LOG_ERROR(format, ...) LOG_TAG(LOG_ERROR, E, __func__, format, ##__VA_ARGS__)
106#define LOG_WARNING(format, ...) LOG_TAG(LOG_WARNING, W, __func__, format, ##__VA_ARGS__)
107#define LOG_INFO(format, ...) LOG_TAG(LOG_INFO, I, __func__, format, ##__VA_ARGS__)
108#define LOG_DEBUG(format, ...) LOG_TAG(LOG_DEBUG, D, __func__, format, ##__VA_ARGS__)
109#endif
110
112#define LOG_TAG_ERROR(tag, format, ...) LOG_TAG(LOG_ERROR, E, tag, format, ##__VA_ARGS__)
113#define LOG_TAG_WARNING(tag, format, ...) LOG_TAG(LOG_WARNING, W, tag, format, ##__VA_ARGS__)
114#define LOG_TAG_INFO(tag, format, ...) LOG_TAG(LOG_INFO, I, tag, format, ##__VA_ARGS__)
115#define LOG_TAG_DEBUG(tag, format, ...) LOG_TAG(LOG_DEBUG, D, tag, format, ##__VA_ARGS__)
116#define LOG_TAG_ALL(tag, format, ...) LOG_TAG(LOG_ALL, V, tag, format, ##__VA_ARGS__)
117
119#define ESP_EARLY_LOGE(tag, format, ...) LOG_TAG_EARLY(LOG_ERROR, E, tag, format "\n", ##__VA_ARGS__)
120#define ESP_EARLY_LOGW(tag, format, ...) LOG_TAG_EARLY(LOG_WARNING, W, tag, format "\n", ##__VA_ARGS__)
121#define ESP_EARLY_LOGI(tag, format, ...) LOG_TAG_EARLY(LOG_INFO, I, tag, format "\n", ##__VA_ARGS__)
122#define ESP_EARLY_LOGD(tag, format, ...) LOG_TAG_EARLY(LOG_DEBUG, D, tag, format "\n", ##__VA_ARGS__)
123#define ESP_EARLY_LOGV(tag, format, ...) LOG_TAG_EARLY(LOG_ALL, V, tag, format "\n", ##__VA_ARGS__)
124
125#ifdef CPU_ESP8266
126#define ESP_LOGE(tag, format, ...) LOG_TAG(LOG_ERROR, E, tag, format "\n", ##__VA_ARGS__)
127#define ESP_LOGW(tag, format, ...) LOG_TAG(LOG_WARNING, W, tag, format "\n", ##__VA_ARGS__)
128#define ESP_LOGI(tag, format, ...) LOG_TAG(LOG_INFO, I, tag, format "\n", ##__VA_ARGS__)
129#define ESP_LOGD(tag, format, ...) LOG_TAG(LOG_DEBUG, D, tag, format "\n", ##__VA_ARGS__)
130#define ESP_LOGV(tag, format, ...) LOG_TAG(LOG_ALL, V, tag, format "\n", ##__VA_ARGS__)
131#endif
132
133#ifdef __cplusplus
134}
135#endif
136
137#endif /* DOXYGEN */
138
Adds include for missing inttype definitions.
uint32_t system_get_time_ms(void)
Time since boot in ms (32bit version)