From 84996130b7b8bb6b5ab6552a22bd024bc6ae6565 Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Wed, 28 Jan 2026 08:58:28 +0000 Subject: [PATCH] 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. --- Makefile | 2 +- include/arl/lib/base.h | 28 +++++++++++++++++++++++++--- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 029b0d0..4b8cfb4 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ OBJECTS:=$(patsubst %,$(DIST)/%.o, $(UNITS)) LDFLAGS= 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 MODE=release diff --git a/include/arl/lib/base.h b/include/arl/lib/base.h index 799d8af..3602e21 100644 --- a/include/arl/lib/base.h +++ b/include/arl/lib/base.h @@ -33,13 +33,35 @@ typedef double f64; #define MIN(A, B) ((A) > (B) ? (B) : (A)) #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 \ { \ - fprintf(stderr, "FAIL: "); \ fprintf(stderr, __VA_ARGS__); \ - assert(0); \ + } while (0); + +#define FAIL(...) \ + do \ + { \ + LOG_ERR("FAIL: "); \ + LOG_ERR(__VA_ARGS__); \ + assert(0); \ } while (0) + #endif /* Copyright (C) 2026 Aryadev Chavali