summaryrefslogtreecommitdiff
path: root/include/al/log.h
blob: cf53503dd3b75494f9c3e6417c563ef56a0aea30 (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
#ifndef _AL_LOG_H
#define _AL_LOG_H

#include <al/types.h>
#include <al/lib.h>

#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
#define __LOCATION__ __FILENAME__, __LINE__, __FUNCTION__

void al_set_print(s32 (*print_func)(void *, char *), void *userdata);

s32 _al_log(const char *level, const char *section, const char *name, const s32 line, const char *func, const char *fmt, ...);
s32 _al_logv(const char *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("info", section, fmt, ##__VA_ARGS__)
#define al_log_warn(section, fmt, ...) al_log("warn", section, fmt, ##__VA_ARGS__)
#define al_log_error(section, fmt, ...) al_log("error", section, fmt, ##__VA_ARGS__)
#ifdef _DEBUG_
#define al_log_debug(section, fmt, ...) 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