* 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:04:06 +0000 (22:04 +0200)
 -> still no strbuf needed
 -> no problems with race conditions causing clashes between several lines

citadel/sysdep.c

index 09b66f286cecabb0f6c2ff4345340a1d303f19b4..a2c74f31e8f11309bf55be1e56fd2f6ef2ea0fbf 100644 (file)
@@ -122,6 +122,9 @@ void vCtdlLogPrintf(enum LogLevel loglevel, const char *format, va_list arg_ptr)
                ThreadTSD *cTSD = CTP;
                CtdlThreadNode *node = NULL;
                long lwpid = 0;
+               char formatbuf[SIZ];
+               char LWP[64];
+               char SESS[64];
 
                if (cTSD != NULL) {
                        node = cTSD->self;
@@ -137,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);
        }
 }