base: Added some extra logging macros

LOG, LOG_ERR.  LOG_ERR will always compile to a /stderr/ print.  LOG,
on the other hand, may not actually do anything if VERBOSE_LOGS is
not 1.  By default it is 0, so it must be defined when compiling to
enable - hence the adjustment of the Makefile.
This commit is contained in:
2026-01-28 08:58:28 +00:00
parent 0beab4e11d
commit 84996130b7
2 changed files with 26 additions and 4 deletions

View File

@@ -9,7 +9,7 @@ OBJECTS:=$(patsubst %,$(DIST)/%.o, $(UNITS))
LDFLAGS= LDFLAGS=
GFLAGS=-Wall -Wextra -Wpedantic -std=c23 -I./include/ GFLAGS=-Wall -Wextra -Wpedantic -std=c23 -I./include/
DFLAGS=-ggdb -fsanitize=address -fsanitize=undefined DFLAGS=-ggdb -fsanitize=address -fsanitize=undefined -DVERBOSE_LOGS=1
RFLAGS=-O3 RFLAGS=-O3
MODE=release MODE=release

View File

@@ -33,13 +33,35 @@ typedef double f64;
#define MIN(A, B) ((A) > (B) ? (B) : (A)) #define MIN(A, B) ((A) > (B) ? (B) : (A))
#define ARRSIZE(A) ((sizeof(A)) / sizeof((A)[0])) #define ARRSIZE(A) ((sizeof(A)) / sizeof((A)[0]))
#define FAIL(...) \ #ifndef VERBOSE_LOGS
#define VERBOSE_LOGS 0
#endif
#if VERBOSE_LOGS
#define LOG(...) \
do \
{ \
fprintf(stdout, "LOG: "); \
fprintf(stdout, __VA_ARGS__); \
} while (0);
#else
#define LOG(...)
#endif
#define LOG_ERR(...) \
do \ do \
{ \ { \
fprintf(stderr, "FAIL: "); \
fprintf(stderr, __VA_ARGS__); \ fprintf(stderr, __VA_ARGS__); \
assert(0); \ } while (0);
#define FAIL(...) \
do \
{ \
LOG_ERR("FAIL: "); \
LOG_ERR(__VA_ARGS__); \
assert(0); \
} while (0) } while (0)
#endif #endif
/* Copyright (C) 2026 Aryadev Chavali /* Copyright (C) 2026 Aryadev Chavali