add log_printf function

Wed, 19 Jul 2023 20:39:09 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Wed, 19 Jul 2023 20:39:09 +0200
changeset 779
a0e02b70dad1
parent 778
bf53db813cc9
child 780
cd1c869720e0

add log_printf function

dav/sync.c file | annotate | diff | comparison | revisions
dav/sync.h file | annotate | diff | comparison | revisions
--- a/dav/sync.c	Wed Jul 19 20:31:01 2023 +0200
+++ b/dav/sync.c	Wed Jul 19 20:39:09 2023 +0200
@@ -70,6 +70,8 @@
 
 static int sync_shutdown = 0;
 
+static FILE *synclog;
+
 static void xmlerrorfnc(void * c, const char * msg, ... ) {
     va_list ap;
     va_start(ap, msg);
@@ -89,6 +91,24 @@
 };
 static size_t numdefprops = 8 ;
 
+void log_printf(const char *loglevel, const char *fmt, ...) {
+    const char *sp = " ";
+    if(!loglevel) {
+        loglevel = "";
+        sp = "";
+    }
+    
+    va_list ap;
+    va_start(ap, fmt);
+    cxmutstr str = cx_vasprintf(fmt, ap);
+    va_end(ap);
+    
+    printf("%s\n", str.ptr);
+    if(synclog) {
+        fprintf(synclog, "%s%s%s\n", loglevel, sp, str.ptr);
+    }
+}
+
 /*
  * strcmp version that works with NULL pointers
  */
--- a/dav/sync.h	Wed Jul 19 20:31:01 2023 +0200
+++ b/dav/sync.h	Wed Jul 19 20:39:09 2023 +0200
@@ -105,6 +105,8 @@
 int cmd_push(CmdArgs *args, DavBool outgoing, DavBool archive);
 int cmd_restore(CmdArgs *args);
 
+void log_printf(const char *loglevel, const char *fmt, ...);
+
 void print_outgoing(
         CmdArgs *args,
         CxList *ls_new,

mercurial