VSF Documented
esp_log.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Copyright(C)2009-2026 by VSF Team *
3 * *
4 * Licensed under the Apache License, Version 2.0 (the "License"); *
5 * you may not use this file except in compliance with the License. *
6 * You may obtain a copy of the License at *
7 * *
8 * http://www.apache.org/licenses/LICENSE-2.0 *
9 * *
10 * Unless required by applicable law or agreed to in writing, software *
11 * distributed under the License is distributed on an "AS IS" BASIS, *
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
13 * See the License for the specific language governing permissions and *
14 * limitations under the License. *
15 * *
16 ****************************************************************************/
17
18/*
19 * Clean-room re-implementation of ESP-IDF public API "esp_log.h".
20 *
21 * Authored from the ESP-IDF v5.x public API reference only. No code or
22 * data is copied from the ESP-IDF source tree. Names, enum values and
23 * macro semantics are preserved so that unmodified ESP-IDF example code
24 * can compile against this header.
25 *
26 * The VSF port forwards all output through vsf_trace, so log lines share
27 * the same stream, coloring and redirection handling as the rest of VSF.
28 */
29
30#ifndef __VSF_ESPIDF_ESP_LOG_H__
31#define __VSF_ESPIDF_ESP_LOG_H__
32
33#include <stdint.h>
34#include <stdarg.h>
35#include <stddef.h>
36
37#ifdef __cplusplus
38extern "C" {
39#endif
40
41/*============================ TYPES =========================================*/
42
43typedef enum {
51
52/* Drop-in replacement for the vprintf-shaped redirection hook.
53 * Returns number of characters written. */
54typedef int (*vprintf_like_t)(const char *, va_list);
55
56/*============================ PROTOTYPES ====================================*/
57
58/* Install tag-specific log level. Tag "*" sets the default level applied to
59 * any tag that does not have its own override. Pass level=ESP_LOG_NONE to
60 * silence a tag. */
61void esp_log_level_set(const char *tag, esp_log_level_t level);
62
63/* Query effective level for a given tag. Unknown tags fall back to the
64 * default level set via tag "*". */
65esp_log_level_t esp_log_level_get(const char *tag);
66
67/* Install a custom output function; the previous one is returned so callers
68 * can chain. Pass NULL to restore the built-in vsf_trace backend. */
70
71/* Emit a log line at the given level. Does nothing if filtered. The VSF
72 * port prefixes each line with "<LEVEL> <TAG>: " and appends the standard
73 * VSF_TRACE_CFG_LINEEND. */
74void esp_log_write(esp_log_level_t level, const char *tag, const char *format, ...)
75#if defined(__GNUC__) || defined(__clang__)
77#endif
78;
79
80void esp_log_writev(esp_log_level_t level, const char *tag, const char *format, va_list args);
81
82/* Timestamp in milliseconds since boot. Monotonic, wraps around at 2^32 ms. */
84
85/* Formatted wall-clock-like timestamp as static string; VSF provides only a
86 * "%08lu" tick representation since there is no RTC baseline. */
87char * esp_log_system_timestamp(void);
88
89/* Early-log helpers exist in ESP-IDF to bypass locking during boot. VSF has
90 * no such distinction, so they are aliased. */
91#define esp_earlylog_write esp_log_write
92
93/*============================ MACROS ========================================*/
94
95/* Compile-time master level gate. Callers may #define LOG_LOCAL_LEVEL
96 * before including this header to pre-filter a translation unit. */
97#ifndef LOG_LOCAL_LEVEL
98# define LOG_LOCAL_LEVEL ESP_LOG_VERBOSE
99#endif
100
101/* Check both compile-time and run-time gates. */
102#define ESP_LOG_LEVEL_LOCAL(level, tag, format, ...) \
103 do { \
104 if ((level) <= LOG_LOCAL_LEVEL) { \
105 esp_log_write((level), (tag), format, ##__VA_ARGS__); \
106 } \
107 } while (0)
108
109#define ESP_LOG_LEVEL(level, tag, format, ...) \
110 ESP_LOG_LEVEL_LOCAL(level, tag, format, ##__VA_ARGS__)
111
112#define ESP_LOGE(tag, format, ...) ESP_LOG_LEVEL_LOCAL(ESP_LOG_ERROR, tag, format, ##__VA_ARGS__)
113#define ESP_LOGW(tag, format, ...) ESP_LOG_LEVEL_LOCAL(ESP_LOG_WARN, tag, format, ##__VA_ARGS__)
114#define ESP_LOGI(tag, format, ...) ESP_LOG_LEVEL_LOCAL(ESP_LOG_INFO, tag, format, ##__VA_ARGS__)
115#define ESP_LOGD(tag, format, ...) ESP_LOG_LEVEL_LOCAL(ESP_LOG_DEBUG, tag, format, ##__VA_ARGS__)
116#define ESP_LOGV(tag, format, ...) ESP_LOG_LEVEL_LOCAL(ESP_LOG_VERBOSE, tag, format, ##__VA_ARGS__)
117
118/* The EARLY variants exist only for API compatibility; they share the same
119 * path in this port because there is no pre-scheduler window distinct from
120 * post-scheduler in VSF's cooperative model. */
121#define ESP_EARLY_LOGE(tag, format, ...) ESP_LOGE(tag, format, ##__VA_ARGS__)
122#define ESP_EARLY_LOGW(tag, format, ...) ESP_LOGW(tag, format, ##__VA_ARGS__)
123#define ESP_EARLY_LOGI(tag, format, ...) ESP_LOGI(tag, format, ##__VA_ARGS__)
124#define ESP_EARLY_LOGD(tag, format, ...) ESP_LOGD(tag, format, ##__VA_ARGS__)
125#define ESP_EARLY_LOGV(tag, format, ...) ESP_LOGV(tag, format, ##__VA_ARGS__)
126
127#define ESP_DRAM_LOGE(tag, format, ...) ESP_LOGE(tag, format, ##__VA_ARGS__)
128#define ESP_DRAM_LOGW(tag, format, ...) ESP_LOGW(tag, format, ##__VA_ARGS__)
129#define ESP_DRAM_LOGI(tag, format, ...) ESP_LOGI(tag, format, ##__VA_ARGS__)
130#define ESP_DRAM_LOGD(tag, format, ...) ESP_LOGD(tag, format, ##__VA_ARGS__)
131#define ESP_DRAM_LOGV(tag, format, ...) ESP_LOGV(tag, format, ##__VA_ARGS__)
132
133#ifdef __cplusplus
134}
135#endif
136
137#endif // __VSF_ESPIDF_ESP_LOG_H__
vprintf_like_t esp_log_set_vprintf(vprintf_like_t func)
Definition esp_log_port.c:123
char * esp_log_system_timestamp(void)
Definition esp_log_port.c:135
esp_log_level_t esp_log_level_get(const char *tag)
Definition esp_log_port.c:117
esp_log_level_t
Definition esp_log.h:43
@ ESP_LOG_NONE
Definition esp_log.h:44
@ ESP_LOG_WARN
Definition esp_log.h:46
@ ESP_LOG_VERBOSE
Definition esp_log.h:49
@ ESP_LOG_DEBUG
Definition esp_log.h:48
@ ESP_LOG_INFO
Definition esp_log.h:47
@ ESP_LOG_ERROR
Definition esp_log.h:45
int(* vprintf_like_t)(const char *, va_list)
Definition esp_log.h:54
void esp_log_level_set(const char *tag, esp_log_level_t level)
Definition esp_log_port.c:93
uint32_t esp_log_timestamp(void)
Definition esp_log_port.c:130
void esp_log_writev(esp_log_level_t level, const char *tag, const char *format, va_list args)
Definition esp_log_port.c:167
void esp_log_write(esp_log_level_t level, const char *tag, const char *format,...)
Definition esp_log_port.c:222
__attribute__((weak))
Definition handlers.c:10
unsigned uint32_t
Definition stdint.h:9
#define printf
Definition stdio.h:75
SDL_PixelFormat format
Definition vsf_sdl2_pixelformat.c:32
Generated from commit: vsfteam/vsf@015f4d1