summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Opalach <andrew@akon.city> 2025-03-15 19:55:08 -0400
committerAndrew Opalach <andrew@akon.city> 2025-03-15 19:55:08 -0400
commit02c3cf915ed7eb50db3d16b3f3ade71ecb8872ef (patch)
treea32a8be0d3bfc79920de7fa95aaf98e2bc20fbee
parent7feaa9ec9090129f78b7aed868b6a0b4359e686c (diff)
downloadlibalabaster-02c3cf915ed7eb50db3d16b3f3ade71ecb8872ef.tar.gz
libalabaster-02c3cf915ed7eb50db3d16b3f3ade71ecb8872ef.tar.bz2
libalabaster-02c3cf915ed7eb50db3d16b3f3ade71ecb8872ef.zip
log: Add TRACE and new shorthands
Signed-off-by: Andrew Opalach <andrew@akon.city>
-rw-r--r--include/al/log.h33
-rw-r--r--src/log.c4
2 files changed, 31 insertions, 6 deletions
diff --git a/include/al/log.h b/include/al/log.h
index fbd5e48..da3f21d 100644
--- a/include/al/log.h
+++ b/include/al/log.h
@@ -3,6 +3,10 @@
// https://pubs.opengroup.org/onlinepubs/009695399/functions/fprintf.html
+#ifndef AL_LOG_SECTION
+#define AL_LOG_SECTION NULL
+#endif
+
#include <al/types.h>
#include <al/lib.h>
@@ -14,7 +18,8 @@ enum {
AL_LOG_INFO = 0,
AL_LOG_WARN,
AL_LOG_ERROR,
- AL_LOG_DEBUG
+ AL_LOG_DEBUG,
+ AL_LOG_TRACE
};
void al_set_print(s32 (*print_func)(void *, u8, char *), void *userdata);
@@ -25,12 +30,35 @@ s32 _al_logv(u8 level, const char *section, const char *name, const s32 line, co
#define al_log(level, section, fmt, ...) _al_log(level, section, __LOCATION__, fmt, ##__VA_ARGS__)
#define al_logv(level, section, fmt, args) _al_logv(level, section, __LOCATION__, fmt, args)
+#define info(fmt, ...) al_log(AL_LOG_INFO, AL_LOG_SECTION, fmt, ##__VA_ARGS__)
+#define warn(fmt, ...) al_log(AL_LOG_WARN, AL_LOG_SECTION, fmt, ##__VA_ARGS__)
+#define error(fmt, ...) al_log(AL_LOG_ERROR, AL_LOG_SECTION, fmt, ##__VA_ARGS__)
+#ifdef _DEBUG_
+#define debug(fmt, ...) al_log(AL_LOG_DEBUG, AL_LOG_SECTION, fmt, ##__VA_ARGS__)
+#else
+#define debug(fmt, ...) al_log_nop(AL_LOG_SECTION, fmt, ##__VA_ARGS__)
+#endif
+#ifdef AL_LOG_ENABLE_TRACE
+#define trace(fmt, ...) al_log(AL_LOG_TRACE, AL_LOG_SECTION, fmt, ##__VA_ARGS__)
+#else
+#define trace(fmt, ...) al_log_nop(AL_LOG_SECTION, fmt, ##__VA_ARGS__)
+#endif
+
+// TMP
#define al_log_info(section, fmt, ...) al_log(AL_LOG_INFO, section, fmt, ##__VA_ARGS__)
#define al_log_warn(section, fmt, ...) al_log(AL_LOG_WARN, section, fmt, ##__VA_ARGS__)
#define al_log_error(section, fmt, ...) al_log(AL_LOG_ERROR, section, fmt, ##__VA_ARGS__)
#ifdef _DEBUG_
#define al_log_debug(section, fmt, ...) al_log(AL_LOG_DEBUG, section, fmt, ##__VA_ARGS__)
#else
+#define al_log_debug(section, fmt, ...) al_log_nop(section, fmt, ##__VA_ARGS__)
+#endif
+#ifdef AL_LOG_ENABLE_TRACE
+#define al_log_trace(section, fmt, ...) al_log(AL_LOG_TRACE, section, fmt, ##__VA_ARGS__)
+#else
+#define al_log_trace(section, fmt, ...) al_log_nop(section, fmt, ##__VA_ARGS__)
+#endif
+
AL_UNUSED_FUNCTION_PUSH
static inline s32 al_log_nop(const char *section, const char *fmt, ...)
@@ -40,7 +68,4 @@ static inline s32 al_log_nop(const char *section, const char *fmt, ...)
AL_UNUSED_FUNCTION_POP
-#define al_log_debug(section, fmt, ...) al_log_nop(section, fmt, ##__VA_ARGS__)
-#endif
-
#endif // _AL_LOG_H
diff --git a/src/log.c b/src/log.c
index 55dcad5..3c0466a 100644
--- a/src/log.c
+++ b/src/log.c
@@ -1,5 +1,4 @@
#include "../include/al/log.h"
-#include "../include/al/macros.h"
//#define AL_LOG_SKIP
#define AL_LOG_TEMPLATE "%s:%d %s(): %s -> "
@@ -21,7 +20,8 @@ static const char *levels[] = {
[AL_LOG_INFO] = "info",
[AL_LOG_WARN] = "warn",
[AL_LOG_ERROR] = "error",
- [AL_LOG_DEBUG] = "debug"
+ [AL_LOG_DEBUG] = "debug",
+ [AL_LOG_TRACE] = "trace"
};
#ifndef AL_LOG_SKIP