diff options
author | Omniscient <17525998+omnisci3nce@users.noreply.github.com> | 2024-02-24 22:47:46 +1100 |
---|---|---|
committer | Omniscient <17525998+omnisci3nce@users.noreply.github.com> | 2024-02-24 22:47:46 +1100 |
commit | 7b3afcaf77f96e7d62f6cd1623ead7f17512d79f (patch) | |
tree | b5f82c64e9c06a84e4d095ab4ac48712e860b673 /src/log.h | |
parent | b047be5252aeb981faea077409c1768fda0301d9 (diff) |
repo init. partial port of existing code
Diffstat (limited to 'src/log.h')
-rw-r--r-- | src/log.h | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/log.h b/src/log.h new file mode 100644 index 0000000..e7a90ea --- /dev/null +++ b/src/log.h @@ -0,0 +1,54 @@ +#pragma once + +#include <stdbool.h> + +#define ERROR_EXIT(...) \ + { \ + fprintf(stderr, __VA_ARGS__); \ + exit(1); \ + } + +#define LOG_WARN_ENABLED 1 +#define LOG_INFO_ENABLED 1 + +#ifdef CRELEASE +#define LOG_DEBUG_ENABLED 0 +#define LOG_TRACE_ENABLED 0 +#else +#define LOG_DEBUG_ENABLED 1 +#define LOG_TRACE_ENABLED 1 +#endif + +typedef enum log_level { + LOG_LEVEL_FATAL = 0, + LOG_LEVEL_ERROR = 1, + LOG_LEVEL_WARN = 2, + LOG_LEVEL_INFO = 3, + LOG_LEVEL_DEBUG = 4, + LOG_LEVEL_TRACE = 5, +} log_level; + +bool logger_init(); +void logger_shutdown(); + +// TODO: macro that outputs logger macros for a specific subsystem or string prefix e.g. "MEMORY" -> +// logs now have more context potentially have line numbers too? + +void log_output(log_level level, const char* message, ...); + +#define FATAL(message, ...) log_output(LOG_LEVEL_FATAL, message, ##__VA_ARGS__); +#define ERROR(message, ...) log_output(LOG_LEVEL_ERROR, message, ##__VA_ARGS__); +#define WARN(message, ...) log_output(LOG_LEVEL_WARN, message, ##__VA_ARGS__); +#define INFO(message, ...) log_output(LOG_LEVEL_INFO, message, ##__VA_ARGS__); + +#if LOG_DEBUG_ENABLED == 1 +#define DEBUG(message, ...) log_output(LOG_LEVEL_DEBUG, message, ##__VA_ARGS__); +#else +#define DEBUG(message, ...) +#endif + +#if LOG_TRACE_ENABLED == 1 +#define TRACE(message, ...) log_output(LOG_LEVEL_TRACE, message, ##__VA_ARGS__); +#else +#define TRACE(message, ...) +#endif
\ No newline at end of file |