aboutsummaryrefslogtreecommitdiffstats
path: root/core/logging.h
blob: 81465929c85a35ac5fdcb3a1ddbacacf44d9fe36 (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 CORE_LOGGING_H
#define CORE_LOGGING_H

#include <stdio.h>

#include "opthelpers.h"


enum class LogLevel {
    Disable,
    Error,
    Warning,
    Trace
};
extern LogLevel gLogLevel;

extern FILE *gLogFile;


#if !defined(_WIN32) && !defined(__ANDROID__)
#define TRACE(...) do {                                                       \
    if UNLIKELY(gLogLevel >= LogLevel::Trace)                                 \
        fprintf(gLogFile, "[ALSOFT] (II) " __VA_ARGS__);                      \
} while(0)

#define WARN(...) do {                                                        \
    if UNLIKELY(gLogLevel >= LogLevel::Warning)                               \
        fprintf(gLogFile, "[ALSOFT] (WW) " __VA_ARGS__);                      \
} while(0)

#define ERR(...) do {                                                         \
    if UNLIKELY(gLogLevel >= LogLevel::Error)                                 \
        fprintf(gLogFile, "[ALSOFT] (EE) " __VA_ARGS__);                      \
} while(0)

#else

#ifdef __USE_MINGW_ANSI_STDIO
[[gnu::format(gnu_printf,3,4)]]
#else
[[gnu::format(printf,3,4)]]
#endif
void al_print(LogLevel level, FILE *logfile, const char *fmt, ...);

#define TRACE(...) al_print(LogLevel::Trace, gLogFile, "[ALSOFT] (II) " __VA_ARGS__)

#define WARN(...) al_print(LogLevel::Warning, gLogFile, "[ALSOFT] (WW) " __VA_ARGS__)

#define ERR(...) al_print(LogLevel::Error, gLogFile, "[ALSOFT] (EE) " __VA_ARGS__)
#endif

#endif /* CORE_LOGGING_H */