comparison libfdproto/log.c @ 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 79dd22145f52
children a22d9e907d48
comparison
equal deleted inserted replaced
1242:b25ca6134bdc 1243:7c5f662c4eef
92 /* Do we need to trace this ? */ 92 /* Do we need to trace this ? */
93 if (printlevel < fd_g_debug_lvl) 93 if (printlevel < fd_g_debug_lvl)
94 return; 94 return;
95 95
96 /* add timestamp */ 96 /* add timestamp */
97 printf("%s ", fd_log_time(NULL, buf, sizeof(buf))); 97 printf("%s ", fd_log_time(NULL, buf, sizeof(buf),
98 98 #if (defined(DEBUG) && !defined(DEBUG_WITHOUT_META))
99 1, 1
100 #else /* (defined(DEBUG) && !defined(DEBUG_WITHOUT_META)) */
101 0, 0
102 #endif /* (defined(DEBUG) && !defined(DEBUG_WITHOUT_META)) */
103 ));
99 /* Use colors on stdout ? */ 104 /* Use colors on stdout ? */
100 if (!use_colors) { 105 if (!use_colors) {
101 if (isatty(STDOUT_FILENO)) 106 if (isatty(STDOUT_FILENO))
102 use_colors = 1; 107 use_colors = 1;
103 else 108 else
181 CHECK_POSIX_DO( pthread_setspecific(fd_log_thname, val), /* continue */); 186 CHECK_POSIX_DO( pthread_setspecific(fd_log_thname, val), /* continue */);
182 return; 187 return;
183 } 188 }
184 189
185 /* Write time into a buffer */ 190 /* Write time into a buffer */
186 char * fd_log_time ( struct timespec * ts, char * buf, size_t len ) 191 char * fd_log_time ( struct timespec * ts, char * buf, size_t len, int incl_date, int incl_ms )
187 { 192 {
188 int ret; 193 int ret;
189 size_t offset = 0; 194 size_t offset = 0;
190 struct timespec tp; 195 struct timespec tp;
191 struct tm tm; 196 struct tm tm;
198 return buf; 203 return buf;
199 } 204 }
200 ts = &tp; 205 ts = &tp;
201 } 206 }
202 207
203 offset += strftime(buf + offset, len - offset, "%D,%T", localtime_r( &ts->tv_sec , &tm )); 208 offset += strftime(buf + offset, len - offset, incl_date?"%D,%T":"%T", localtime_r( &ts->tv_sec , &tm ));
204 offset += snprintf(buf + offset, len - offset, ".%6.6ld", ts->tv_nsec / 1000); 209 if (incl_ms)
210 offset += snprintf(buf + offset, len - offset, ".%6.6ld", ts->tv_nsec / 1000);
205 211
206 return buf; 212 return buf;
207 } 213 }
208 214
209 215
"Welcome to our mercurial repository"