* vCtdlLogPrintf(): combine the server data plus the application format string into...
authorWilfried Goesgens <dothebart@citadel.org>
Wed, 13 Oct 2010 19:51:27 +0000 (21:51 +0200)
committerWilfried Goesgens <dothebart@citadel.org>
Wed, 13 Oct 2010 20:15:53 +0000 (22:15 +0200)
 -> still no strbuf needed
 -> no problems with race conditions causing clashes between several lines

citadel/sysdep.c

index 10a955a6009df09997e472fd02df25c271a70631..2e43b66bb0c472ddfae6558e3e7661cb7b911e80 100644 (file)
@@ -140,27 +140,30 @@ void vCtdlLogPrintf(enum LogLevel loglevel, const char *format, va_list arg_ptr)
                unixtime = tv.tv_sec;
                localtime_r(&unixtime, &tim);
 
-               fprintf(stderr,
-                       "%04d/%02d/%02d %2d:%02d:%02d.%06ld ",
-                       tim.tm_year + 1900, tim.tm_mon + 1,
-                       tim.tm_mday, tim.tm_hour, tim.tm_min,
-                       tim.tm_sec, (long)tv.tv_usec
-               );
-
+               *LWP = '\0';
                if (lwpid != 0) {
-                       fprintf(stderr, "[LWP:%ld] ", lwpid);
+                       snprintf(LWP, 64, "[LWP:%ld] ", lwpid);
                }
                        
+               *SESS = '\0';
                if (CCC != NULL) {
                        if (CCC->cs_pid != 0) {
-                               fprintf(stderr, "[%3d] ", CCC->cs_pid);
+                               snprintf(SESS, 64, " [%3d] ", CCC->cs_pid);
                        }
                        else if (CCC->user.usernum != 0) {
-                               fprintf(stderr, "[:%ld] ", CCC->user.usernum);
+                               snprintf(SESS, 64, " [:%ld] ", CCC->user.usernum);
                        }
                }
 
-               vfprintf(stderr, format, arg_ptr);   
+               snprintf(formatbuf, SIZ, 
+                        "%04d/%02d/%02d %2d:%02d:%02d.%06ld %s%s%s",
+                        tim.tm_year + 1900, tim.tm_mon + 1,
+                        tim.tm_mday, tim.tm_hour, tim.tm_min,
+                        tim.tm_sec, (long)tv.tv_usec, 
+                        LWP, SESS, format
+               );
+
+               vfprintf(stderr, formatbuf, arg_ptr);   
                fflush(stderr);
        }
 }