log command line arguments

Thu, 20 Jul 2023 22:15:01 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Thu, 20 Jul 2023 22:15:01 +0200
changeset 784
592ff4ca2aaa
parent 783
36a7f2ea7d12
child 785
645f7e802873

log command line arguments

dav/sync.c file | annotate | diff | comparison | revisions
--- a/dav/sync.c	Thu Jul 20 21:55:45 2023 +0200
+++ b/dav/sync.c	Thu Jul 20 22:15:01 2023 +0200
@@ -72,6 +72,9 @@
 
 static FILE *synclog;
 
+static int orig_argc;
+static char **orig_argv;
+
 static void xmlerrorfnc(void * c, const char * msg, ... ) {
     va_list ap;
     va_start(ap, msg);
@@ -141,6 +144,19 @@
         if(!synclog) {
             fprintf(stderr, "Cannot open logfile %s: %s\n", lf_path, strerror(errno));
             ret = 1;
+        } else {
+            time_t t = time(NULL);
+            char *now = ctime(&t);
+            size_t len = strlen(now);
+            if(now[len-1] == '\n') {
+                len--;
+            }
+            
+            fprintf(synclog, "[%.*s] ", (int)len, now);
+            for(int i=0;i<orig_argc;i++) {
+                fprintf(synclog, "%s ", orig_argv[i]);
+            }
+            fprintf(synclog, "\n");
         }
         if(lf_path_fr) {
             free(lf_path_fr);
@@ -246,6 +262,9 @@
 #endif
 
 int dav_sync_main(int argc, char **argv) {
+    orig_argc = argc;
+    orig_argv = argv;
+    
     if(argc < 2) {
         fprintf(stderr, "Missing command\n");
         print_usage(argv[0]);

mercurial