From 957c64c7b8b5e98d8a03dd84c7e27e7991fb9dbc Mon Sep 17 00:00:00 2001 From: iamcheeseman Date: Mon, 6 Apr 2026 17:04:05 -0400 Subject: Initial commit --- common/log.h | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 common/log.h (limited to 'common/log.h') diff --git a/common/log.h b/common/log.h new file mode 100644 index 0000000..e04b71f --- /dev/null +++ b/common/log.h @@ -0,0 +1,44 @@ +#ifndef __MICRO_LOG_H__ +#define __MICRO_LOG_H__ + +#include +#include + +// Don't include common.h, because this should be included there + +#define log_info(fmt, ...) \ + log_msg(stdout, __FILE__, __LINE__, "info", fmt, ## __VA_ARGS__) +#define log_warn(fmt, ...) \ + log_msg(stderr, __FILE__, __LINE__, "warn", fmt, ## __VA_ARGS__) +#define log_err(fmt, ...) \ + log_msg(stderr, __FILE__, __LINE__, "error", fmt, ## __VA_ARGS__) +#define log_fatal(ec, fmt, ...) \ + (log_msg(stderr, __FILE__, __LINE__, "fatal", fmt, ## __VA_ARGS__), \ + exit(ec)) +#define olog(fmt, ...) \ + _log_plain(stdout, fmt, ## __VA_ARGS__) +#define elog(fmt, ...) \ + _log_plain(stderr, fmt, ## __VA_ARGS__) + +// To be passed as the exit code to log_fatal() +#define ERR_MEM 0x01 +#define ERR_IO 0x02 +#define ERR_MEM_LEAK 0x03 + +#define ERR_GLFW_INIT 0x21 + +#define ERR_OPENGL_INIT 0x31 +#define ERR_OPENGL_SHADER 0x32 + +void log_msg( + FILE *file, + const char *src_name, + int src_line, + const char *type, + const char *fmt, + ... +); + +void _log_plain(FILE *file, const char *fmt, ...); + +#endif // __MICRO_LOG_H__ -- cgit v1.3-2-g0d8e