Browse code

Adding patch to prefix timestamp to stdout/stderr if LogTime is enabled. Patch courtesy of Andreas Schulze.

Micah Snyder authored on 2018/03/01 01:03:17
Showing 1 changed files
... ...
@@ -391,16 +391,17 @@ int logg(const char *str, ...)
391 391
             /* Need to avoid logging time for verbose messages when logverbose
392 392
                is not set or we get a bunch of timestamps in the log without
393 393
                newlines... */
394
-	    if(logg_time && ((*buff != '*') || logg_verbose)) {
395
-	        char timestr[32];
396
-		time(&currtime);
397
-		cli_ctime(&currtime, timestr, sizeof(timestr));
398
-		/* cut trailing \n */
399
-		timestr[strlen(timestr)-1] = '\0';
400
-		fprintf(logg_fp, "%s -> ", timestr);
401
-	    }
402
-
403
-	    if(*buff == '!') {
394
+		if (logg_time && ((*buff != '*') || logg_verbose))
395
+		{
396
+			char timestr[32];
397
+			time(&currtime);
398
+			cli_ctime(&currtime, timestr, sizeof(timestr));
399
+			/* cut trailing \n */
400
+			timestr[strlen(timestr) - 1] = '\0';
401
+			fprintf(logg_fp, "%s -> ", timestr);
402
+		}
403
+
404
+		if(*buff == '!') {
404 405
 		fprintf(logg_fp, "ERROR: %s", buff + 1);
405 406
 		flush = 1;
406 407
 	    } else if(*buff == '^') {
... ...
@@ -418,10 +419,25 @@ int logg(const char *str, ...)
418 418
 		fflush(logg_fp);
419 419
 	}
420 420
 
421
-    if(logg_foreground) {
422
-	if(buff[0] != '#')
423
-	    mprintf("%s", buff);
424
-    }
421
+	if (logg_foreground)
422
+	{
423
+		if (buff[0] != '#')
424
+		{
425
+			if (logg_time)
426
+			{
427
+				char timestr[32];
428
+				time(&currtime);
429
+				cli_ctime(&currtime, timestr, sizeof(timestr));
430
+				/* cut trailing \n */
431
+				timestr[strlen(timestr) - 1] = '\0';
432
+				mprintf("%s -> %s", timestr, buff);
433
+			}
434
+			else
435
+			{
436
+				mprintf("%s", buff);
437
+			}
438
+		}
439
+	}
425 440
 
426 441
 #if defined(USE_SYSLOG) && !defined(C_AIX)
427 442
     if(logg_syslog) {