changeset 1243:7c5f662c4eef

Shortened log timestamp format when DEBUG_WITHOUT_META is defined
author Sebastien Decugis <sdecugis@freediameter.net>
date Mon, 11 Nov 2013 14:55:10 +0800
parents b25ca6134bdc
children 24a03140a6aa
files include/freeDiameter/libfdproto.h libfdproto/log.c
diffstat 2 files changed, 14 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/include/freeDiameter/libfdproto.h	Mon Nov 11 14:42:02 2013 +0800
+++ b/include/freeDiameter/libfdproto.h	Mon Nov 11 14:55:10 2013 +0800
@@ -182,6 +182,8 @@
  *  ts	 	: The timestamp to log, or NULL for "now"
  *  buf 	: An array where the time must be stored
  *  len		: size of the buffer
+ *  incl_date   : The day of year is included in the output
+ *  incl_ms     : millisecond value is included in the output
  *
  * DESCRIPTION: 
  *  Writes the timestamp (in human readable format) in a buffer. 
@@ -189,7 +191,7 @@
  * RETURN VALUE:
  *  pointer to buf.
  */
-char * fd_log_time ( struct timespec * ts, char * buf, size_t len );
+char * fd_log_time ( struct timespec * ts, char * buf, size_t len, int incl_date, int incl_ms );
 
 /*
  * FUNCTION:    fd_log_handler_register
--- a/libfdproto/log.c	Mon Nov 11 14:42:02 2013 +0800
+++ b/libfdproto/log.c	Mon Nov 11 14:55:10 2013 +0800
@@ -94,8 +94,13 @@
     	return;
 
     /* add timestamp */
-    printf("%s  ", fd_log_time(NULL, buf, sizeof(buf)));
-    
+    printf("%s  ", fd_log_time(NULL, buf, sizeof(buf), 
+#if (defined(DEBUG) && !defined(DEBUG_WITHOUT_META))
+    	1, 1
+#else /* (defined(DEBUG) && !defined(DEBUG_WITHOUT_META)) */
+        0, 0
+#endif /* (defined(DEBUG) && !defined(DEBUG_WITHOUT_META)) */
+	    ));
     /* Use colors on stdout ? */
     if (!use_colors) {
 	if (isatty(STDOUT_FILENO))
@@ -183,7 +188,7 @@
 }
 
 /* Write time into a buffer */
-char * fd_log_time ( struct timespec * ts, char * buf, size_t len )
+char * fd_log_time ( struct timespec * ts, char * buf, size_t len, int incl_date, int incl_ms )
 {
 	int ret;
 	size_t offset = 0;
@@ -200,8 +205,9 @@
 		ts = &tp;
 	}
 	
-	offset += strftime(buf + offset, len - offset, "%D,%T", localtime_r( &ts->tv_sec , &tm ));
-	offset += snprintf(buf + offset, len - offset, ".%6.6ld", ts->tv_nsec / 1000);
+	offset += strftime(buf + offset, len - offset, incl_date?"%D,%T":"%T", localtime_r( &ts->tv_sec , &tm ));
+	if (incl_ms)
+		offset += snprintf(buf + offset, len - offset, ".%6.6ld", ts->tv_nsec / 1000);
 
 	return buf;
 }
"Welcome to our mercurial repository"