2018-01-11 20:17:02 -08:00
|
|
|
#ifndef LOGGING_H
|
|
|
|
#define LOGGING_H
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2019-01-07 01:13:06 -08:00
|
|
|
#include "opthelpers.h"
|
|
|
|
|
2018-01-11 20:17:02 -08:00
|
|
|
|
2020-09-28 00:40:30 -07:00
|
|
|
enum class LogLevel {
|
|
|
|
Disable,
|
|
|
|
Error,
|
|
|
|
Warning,
|
|
|
|
Trace,
|
|
|
|
Ref
|
2018-01-11 20:17:02 -08:00
|
|
|
};
|
2018-12-09 15:07:44 -08:00
|
|
|
extern LogLevel gLogLevel;
|
2018-01-11 20:17:02 -08:00
|
|
|
|
2020-09-28 11:34:24 -07:00
|
|
|
extern FILE *gLogFile;
|
|
|
|
|
|
|
|
|
|
|
|
#if !defined(_WIN32) && !defined(__ANDROID__)
|
2018-01-11 20:17:02 -08:00
|
|
|
#define TRACE(...) do { \
|
2020-09-28 00:40:30 -07:00
|
|
|
if UNLIKELY(gLogLevel >= LogLevel::Trace) \
|
2020-09-28 11:34:24 -07:00
|
|
|
fprintf(gLogFile, "[ALSOFT] (II) " __VA_ARGS__); \
|
2018-01-11 20:17:02 -08:00
|
|
|
} while(0)
|
|
|
|
|
|
|
|
#define WARN(...) do { \
|
2020-09-28 00:40:30 -07:00
|
|
|
if UNLIKELY(gLogLevel >= LogLevel::Warning) \
|
2020-09-28 11:34:24 -07:00
|
|
|
fprintf(gLogFile, "[ALSOFT] (WW) " __VA_ARGS__); \
|
2018-01-11 20:17:02 -08:00
|
|
|
} while(0)
|
|
|
|
|
|
|
|
#define ERR(...) do { \
|
2020-09-28 00:40:30 -07:00
|
|
|
if UNLIKELY(gLogLevel >= LogLevel::Error) \
|
2020-09-28 11:34:24 -07:00
|
|
|
fprintf(gLogFile, "[ALSOFT] (EE) " __VA_ARGS__); \
|
2018-01-11 20:17:02 -08:00
|
|
|
} while(0)
|
|
|
|
|
2020-09-28 11:34:24 -07:00
|
|
|
#else
|
|
|
|
|
|
|
|
[[gnu::format(printf,3,4)]] 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
|
|
|
|
|
2018-01-11 20:17:02 -08:00
|
|
|
#endif /* LOGGING_H */
|