summaryrefslogtreecommitdiff
path: root/include/al/log.h
blob: fbd5e489a50f4bd70d570064f134fb80943b88e6 (plain)
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
#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>

#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
};

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 al_log_info(section, fmt, ...) al_log(AL_LOG_INFO, section, fmt, ##__VA_ARGS__)
#define al_log_warn(section, fmt, ...) al_log(AL_LOG_WARN, section, fmt, ##__VA_ARGS__)
#define al_log_error(section, fmt, ...) al_log(AL_LOG_ERROR, section, fmt, ##__VA_ARGS__)
#ifdef _DEBUG_
#define al_log_debug(section, fmt, ...) al_log(AL_LOG_DEBUG, section, fmt, ##__VA_ARGS__)
#else
AL_UNUSED_FUNCTION_PUSH

static inline s32 al_log_nop(const char *section, const char *fmt, ...)
{
    (void)section; (void)fmt; return 0;
}

AL_UNUSED_FUNCTION_POP

#define al_log_debug(section, fmt, ...) al_log_nop(section, fmt, ##__VA_ARGS__)
#endif

#endif // _AL_LOG_H