-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdebug_log.h
More file actions
57 lines (47 loc) · 1.92 KB
/
debug_log.h
File metadata and controls
57 lines (47 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#ifndef DEBUG_LOG_H
#define DEBUG_LOG_H
#include <stdio.h>
#include <stdbool.h>
#include <ctype.h> // For isspace
#include <strings.h> // For strcasecmp
#include <string.h> // For strdup, strtok, strrchr, strlen
// Enum for different modules
typedef enum {
LOG_MODULE_NONE = 0, // Should not be used for logging directly
LOG_MODULE_MAIN,
LOG_MODULE_API_SPEC,
LOG_MODULE_IR,
LOG_MODULE_REGISTRY,
LOG_MODULE_GENERATOR,
LOG_MODULE_CODEGEN,
LOG_MODULE_RENDERER,
LOG_MODULE_DISPATCH,
LOG_MODULE_UTILS,
LOG_MODULE_SDL_VIEWER,
LOG_MODULE_DATABINDING,
// Add new modules above this line
LOG_MODULE_COUNT // Keep this last for array sizing and iteration bounds
} DebugLogModule;
// Function to initialize the logging system
// Reads LVGL_DEBUG_MODULES environment variable.
void debug_log_init(void);
// Parses a comma-separated string of module names and enables them.
// Can be called after debug_log_init() to add more modules from other sources (e.g., command line).
void debug_log_parse_modules_str(const char* modules_str);
// Function to enable logging for a specific module
void debug_log_enable_module(DebugLogModule module);
// Function to disable logging for a specific module
void debug_log_disable_module(DebugLogModule module);
// Function to check if a module is enabled
bool debug_log_is_module_enabled(DebugLogModule module);
// The core logging function (implementation detail, typically not called directly by user code)
void _debug_log_print(DebugLogModule module, const char *file, int line, const char *func, const char *format, ...);
// Macro for logging
// Example: DEBUG_LOG(LOG_MODULE_GENERATOR, "Processing item %d", my_item);
#define DEBUG_LOG(module, format, ...) \
do { \
if (debug_log_is_module_enabled(module)) { \
_debug_log_print(module, __FILE__, __LINE__, __func__, format, ##__VA_ARGS__); \
} \
} while (0)
#endif // DEBUG_LOG_H