udebug: add ulog support
authorJohn Crispin <john@phrozen.org>
Tue, 28 Nov 2023 07:13:49 +0000 (08:13 +0100)
committerFelix Fietkau <nbd@nbd.name>
Tue, 28 Nov 2023 11:08:42 +0000 (12:08 +0100)
Make ulog able to also log via udebug.

Signed-off-by: John Crispin <john@phrozen.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
ulog.c
ulog.h

diff --git a/ulog.c b/ulog.c
index 05946a0c352154c15e1fc4b28e3e8110e668c075..6c2c1f83b302cbb5f383e2d805dc9294061ac76f 100644 (file)
--- a/ulog.c
+++ b/ulog.c
@@ -29,6 +29,7 @@ static int _ulog_facility = -1;
 static int _ulog_threshold = LOG_DEBUG;
 static int _ulog_initialized = 0;
 static const char *_ulog_ident = NULL;
+static struct udebug_buf *udb = NULL;
 
 static const char *ulog_default_ident(void)
 {
@@ -120,6 +121,11 @@ static void ulog_syslog(int priority, const char *fmt, va_list ap)
        vsyslog(priority, fmt, ap);
 }
 
+void ulog_udebug(struct udebug_buf *_udb)
+{
+       udb = _udb;
+}
+
 void ulog_open(int channels, int facility, const char *ident)
 {
        ulog_close();
@@ -149,6 +155,14 @@ void ulog(int priority, const char *fmt, ...)
 {
        va_list ap;
 
+       if (udb) {
+               va_start(ap, fmt);
+               udebug_entry_init(udb);
+               udebug_entry_vprintf(udb, fmt, ap);
+               udebug_entry_add(udb);
+               va_end(ap);
+       }
+
        if (priority > _ulog_threshold)
                return;
 
diff --git a/ulog.h b/ulog.h
index 46d3c77da9c24d8aa355631f61f6d20abfc11a44..0b81cc30f2f6c6f5b9604f1953954c9d4e405df4 100644 (file)
--- a/ulog.h
+++ b/ulog.h
@@ -21,6 +21,8 @@
 
 #include <syslog.h>
 
+#include "udebug.h"
+
 enum {
        ULOG_KMSG   = (1 << 0),
        ULOG_SYSLOG = (1 << 1),
@@ -28,6 +30,7 @@ enum {
 };
 
 void ulog_open(int channels, int facility, const char *ident);
+void ulog_udebug(struct udebug_buf *udb);
 void ulog_close(void);
 
 void ulog_threshold(int threshold);