Add slog logging support and update error handling in various modules

This commit is contained in:
2025-08-13 20:16:42 +01:00
parent 64c58c0300
commit d62e3119c2
14 changed files with 228 additions and 162 deletions

43
include/log.h Normal file
View File

@@ -0,0 +1,43 @@
//
// Created by claunia on 13/8/25.
//
#ifndef LIBAARUFORMAT_LOG_H
#define LIBAARUFORMAT_LOG_H
#include <stdarg.h>
#include <stdio.h>
// Uncomment to enable tracing
// #define ENABLE_TRACE
// Uncomment to use slog instead of stderr
// #define USE_SLOG
#ifdef ENABLE_TRACE
#ifdef USE_SLOG
#include "slog.h"
#define TRACE(fmt, ...) slog_trace(fmt, ##__VA_ARGS__)
#else
#define TRACE(fmt, ...) fprintf(stderr, "[TRACE] %s:%d:%s(): " fmt "\n", __FILE__, __LINE__, __func__, ##__VA_ARGS__)
#endif
#else
#define TRACE(fmt, ...)
#endif
#include <stdarg.h>
#include <stdio.h>
#ifdef ENABLE_FATAL
#ifdef USE_SLOG
#include "slog.h"
#define FATAL(fmt, ...) slog_fatal(fmt, ##__VA_ARGS__)
#else
#define FATAL(fmt, ...) fprintf(stderr, "[FATAL] %s:%d:%s(): " fmt "\n", __FILE__, __LINE__, __func__, ##__VA_ARGS__)
#endif
#else
#define FATAL(fmt, ...)
#endif
#endif // LIBAARUFORMAT_LOG_H