feat: add basic logging interface
Introduce a lightweight logger interface, allowing clients to register
custom info, warn, and error handlers. Adds initial integration into
transfer_list.h.
Change-Id: Ia2470ce58566385f3c7df068f600d236c09625ca
Signed-off-by: Harrison Mutai <harrison.mutai@arm.com>
diff --git a/src/generic/logging.c b/src/generic/logging.c
new file mode 100644
index 0000000..240a5f7
--- /dev/null
+++ b/src/generic/logging.c
@@ -0,0 +1,57 @@
+/*
+ * Copyright The Transfer List Library Contributors
+ *
+ * SPDX-License-Identifier: MIT OR GPL-2.0-or-later
+ */
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "logging.h"
+
+static struct logger_interface _logger;
+struct logger_interface *logger = NULL;
+
+static void default_log(const char *level, const char *fmt, va_list args)
+{
+ printf("[%s] ", level);
+ vprintf(fmt, args);
+}
+
+static void libtl_info(const char *fmt, ...)
+{
+ va_list args;
+ va_start(args, fmt);
+ default_log("INFO", fmt, args);
+ va_end(args);
+}
+
+static void libtl_warn(const char *fmt, ...)
+{
+ va_list args;
+ va_start(args, fmt);
+ default_log("WARN", fmt, args);
+ va_end(args);
+}
+
+void libtl_error(const char *fmt, ...)
+{
+ va_list args;
+ va_start(args, fmt);
+ default_log("ERROR", fmt, args);
+ va_end(args);
+}
+
+void libtl_register_logger(struct logger_interface *user_logger)
+{
+ if (user_logger != NULL) {
+ logger = user_logger;
+ }
+
+ _logger.info = libtl_info;
+ _logger.warn = libtl_warn;
+ _logger.error = libtl_error;
+
+ logger = &_logger;
+};