feat: ansi codes for logging

This commit is contained in:
2026-05-03 21:09:16 +05:30
parent 7ec85f0797
commit df250ee34d
3 changed files with 10 additions and 3 deletions
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
+10 -3
View File
@@ -3,6 +3,8 @@
#include <string.h> #include <string.h>
#include <stdarg.h> #include <stdarg.h>
/* I took it from stack overflow man stop asking me questions */
#define NARGS(...) NARGS_(__VA_ARGS__, 5, 4, 3, 2, 1, 0) #define NARGS(...) NARGS_(__VA_ARGS__, 5, 4, 3, 2, 1, 0)
#define NARGS_(_5, _4, _3, _2, _1, N, ...) N #define NARGS_(_5, _4, _3, _2, _1, N, ...) N
@@ -12,18 +14,22 @@
#define LOG(...) LOGG(LOG, NARGS(__VA_ARGS__))(__VA_ARGS__) #define LOG(...) LOGG(LOG, NARGS(__VA_ARGS__))(__VA_ARGS__)
void LOG1(char *str) { printf("+ [INFO] %s\n", str); } void LOG1(char *str) { printf("\e[0;34m+ [INFO] \e[0m%s\n", str); }
void LOG2(char *str, char *level) { void LOG2(char *str, char *level) {
if (strcmp(level, "warn") == 0) { if (strcmp(level, "warn") == 0) {
printf("! [WARN] %s\n", str); printf("\e[0;33m! [WARN] \e[0m%s\n", str);
return; return;
} }
if (strcmp(level, "fatal") == 0) { if (strcmp(level, "fatal") == 0) {
printf("!! [FATAL] %s\n", str); printf("\e[0;31m!! [FATAL] \e[0m%s\n", str);
exit(1); exit(1);
} }
if (strcmp(level, "todo") == 0) {
printf("+ [TODO] %s\n", str);
}
} }
@@ -31,6 +37,7 @@ int main()
{ {
LOG("This is a Log"); LOG("This is a Log");
LOG("This is a Warning", "warn"); LOG("This is a Warning", "warn");
LOG("This is a TODO", "todo");
LOG("HELLO", "fatal"); LOG("HELLO", "fatal");
return 0; return 0;
} }