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
|
#ifndef _AL_LOG_H
#define _AL_LOG_H
// https://pubs.opengroup.org/onlinepubs/009695399/functions/fprintf.html
#include <al/types.h>
#include <al/lib.h>
AL_IGNORE_WARNING("-Wunused-variable")
#ifndef AL_LOG_SECTION
static const char *AL_LOG_SECTION_NAME = "";
#else
static const char *AL_LOG_SECTION_NAME = AL_LOG_SECTION;
#endif
AL_IGNORE_WARNING_END
#define __LOCATION__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__), __LINE__, __FUNCTION__
#define AL_LOG_MESSAGE_SIZE 256u
enum {
AL_LOG_INFO = 0,
AL_LOG_WARN,
AL_LOG_ERROR,
AL_LOG_DEBUG,
AL_LOG_TRACE
};
void al_set_print(s32 (*print_func)(void *, u8, char *), void *userdata);
s32 _al_log(u8 level, const char *section, const char *name, const s32 line, const char *func, const char *fmt, ...);
s32 _al_logv(u8 level, const char *section, const char *name, const s32 line, const char *func, const char *fmt, va_list args);
#define al_log(level, section, fmt, ...) _al_log(level, section, __LOCATION__, fmt, ##__VA_ARGS__)
#define al_logv(level, section, fmt, args) _al_logv(level, section, __LOCATION__, fmt, args)
#define log_info(fmt, ...) al_log(AL_LOG_INFO, AL_LOG_SECTION_NAME, fmt, ##__VA_ARGS__)
#define log_warn(fmt, ...) al_log(AL_LOG_WARN, AL_LOG_SECTION_NAME, fmt, ##__VA_ARGS__)
#define log_error(fmt, ...) al_log(AL_LOG_ERROR, AL_LOG_SECTION_NAME, fmt, ##__VA_ARGS__)
#ifdef AL_DEBUG
#define log_debug(fmt, ...) al_log(AL_LOG_DEBUG, AL_LOG_SECTION_NAME, fmt, ##__VA_ARGS__)
#else
#define log_debug(fmt, ...) al_log_nop(AL_LOG_SECTION_NAME, fmt, ##__VA_ARGS__)
#endif
#ifdef AL_LOG_ENABLE_TRACE
#define log_trace(fmt, ...) al_log(AL_LOG_TRACE, AL_LOG_SECTION_NAME, fmt, ##__VA_ARGS__)
#else
#define log_trace(fmt, ...) al_log_nop(AL_LOG_SECTION_NAME, fmt, ##__VA_ARGS__)
#endif
static inline s32 al_log_nop(const char *section, const char *fmt, ...)
{
(void)section; (void)fmt; return 0;
}
#endif // _AL_LOG_H
|