# HG changeset patch # User Sebastien Decugis # Date 1384152910 -28800 # Node ID 7c5f662c4eeff8fd09a9423bab8acc4f42be9c35 # Parent b25ca6134bdc9663c257e05bcf5eee0cee0f4bc6 Shortened log timestamp format when DEBUG_WITHOUT_META is defined diff -r b25ca6134bdc -r 7c5f662c4eef include/freeDiameter/libfdproto.h --- 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 diff -r b25ca6134bdc -r 7c5f662c4eef libfdproto/log.c --- 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; }