Use an enum class for the log level
[openal-soft.git] / alc / logging.h
blob77593779081d1f69ca649f2be0f798cd1724a65e
1 #ifndef LOGGING_H
2 #define LOGGING_H
4 #include <stdio.h>
6 #include "opthelpers.h"
9 extern FILE *gLogFile;
11 [[gnu::format(printf,2,3)]] void al_print(FILE *logfile, const char *fmt, ...);
12 #if !defined(_WIN32)
13 #define AL_PRINT fprintf
14 #else
15 #define AL_PRINT al_print
16 #endif
18 #ifdef __ANDROID__
19 #include <android/log.h>
20 #define LOG_ANDROID(T, ...) __android_log_print(T, "openal", "AL lib: " __VA_ARGS__)
21 #else
22 #define LOG_ANDROID(T, ...) ((void)0)
23 #endif
25 enum class LogLevel {
26 Disable,
27 Error,
28 Warning,
29 Trace,
30 Ref
32 extern LogLevel gLogLevel;
34 #define TRACE(...) do { \
35 if UNLIKELY(gLogLevel >= LogLevel::Trace) \
36 AL_PRINT(gLogFile, "AL lib: (II) " __VA_ARGS__); \
37 LOG_ANDROID(ANDROID_LOG_DEBUG, __VA_ARGS__); \
38 } while(0)
40 #define WARN(...) do { \
41 if UNLIKELY(gLogLevel >= LogLevel::Warning) \
42 AL_PRINT(gLogFile, "AL lib: (WW) " __VA_ARGS__); \
43 LOG_ANDROID(ANDROID_LOG_WARN, __VA_ARGS__); \
44 } while(0)
46 #define ERR(...) do { \
47 if UNLIKELY(gLogLevel >= LogLevel::Error) \
48 AL_PRINT(gLogFile, "AL lib: (EE) " __VA_ARGS__); \
49 LOG_ANDROID(ANDROID_LOG_ERROR, __VA_ARGS__); \
50 } while(0)
52 #endif /* LOGGING_H */