aboutsummaryrefslogtreecommitdiffstats
path: root/alc/logging.h
blob: 1077f08fdc2aa18e3210a07bb17126e2fb67f3c4 (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
47
48
49
50
51
52
#ifndef LOGGING_H
#define LOGGING_H

#include <stdio.h>

#include "opthelpers.h"


extern FILE *gLogFile;

[[gnu::format(printf,2,3)]] void al_print(FILE *logfile, const char *fmt, ...);
#if !defined(_WIN32)
#define AL_PRINT fprintf
#else
#define AL_PRINT al_print
#endif

#ifdef __ANDROID__
#include <android/log.h>
#define LOG_ANDROID(T, ...) __android_log_print(T, "openal", "AL lib: " __VA_ARGS__)
#else
#define LOG_ANDROID(T, ...) ((void)0)
#endif

enum LogLevel {
    NoLog,
    LogError,
    LogWarning,
    LogTrace,
    LogRef
};
extern LogLevel gLogLevel;

#define TRACE(...) do {                                                       \
    if UNLIKELY(gLogLevel >= LogTrace)                                        \
        AL_PRINT(gLogFile, "AL lib: (II) " __VA_ARGS__);                      \
    LOG_ANDROID(ANDROID_LOG_DEBUG, __VA_ARGS__);                              \
} while(0)

#define WARN(...) do {                                                        \
    if UNLIKELY(gLogLevel >= LogWarning)                                      \
        AL_PRINT(gLogFile, "AL lib: (WW) " __VA_ARGS__);                      \
    LOG_ANDROID(ANDROID_LOG_WARN, __VA_ARGS__);                               \
} while(0)

#define ERR(...) do {                                                         \
    if UNLIKELY(gLogLevel >= LogError)                                        \
        AL_PRINT(gLogFile, "AL lib: (EE) " __VA_ARGS__);                      \
    LOG_ANDROID(ANDROID_LOG_ERROR, __VA_ARGS__);                              \
} while(0)

#endif /* LOGGING_H */