diff options
author | Chris Robinson <[email protected]> | 2020-12-17 01:25:33 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2020-12-17 02:47:03 -0800 |
commit | d578bc6cb1b9bce4954ded9b138d51980163c233 (patch) | |
tree | e38c0c3869f80e39693f19ff7c184708ac4e7770 /core/logging.h | |
parent | f0fe57dc5a1b518397688b868592287f49d1afef (diff) |
Move logging to core
Diffstat (limited to 'core/logging.h')
-rw-r--r-- | core/logging.h | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/core/logging.h b/core/logging.h new file mode 100644 index 00000000..b931c27e --- /dev/null +++ b/core/logging.h @@ -0,0 +1,47 @@ +#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 + +[[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 + +#endif /* CORE_LOGGING_H */ |