1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-11-10 21:38:50 +01:00

common: Change log_clock to printf style.

* common/logging.c (log_clock): Use do_logv.

Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
Werner Koch 2017-11-15 14:46:14 +01:00
parent d05e54ac4f
commit 8704304699
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B
2 changed files with 17 additions and 5 deletions

View File

@ -1039,14 +1039,16 @@ log_printsexp () {}
is found in sexputils.c
*/
/* Print a microsecond timestamp followed by STRING. */
/* Print a microsecond timestamp followed by a FORMAT. */
void
log_clock (const char *string)
log_clock (const char *fmt, ...)
{
#if ENABLE_LOG_CLOCK
static unsigned long long initial;
struct timespec tv;
unsigned long long now;
char clockbuf[50];
va_list arg_ptr;
if (clock_gettime (CLOCK_REALTIME, &tv))
{
@ -1059,10 +1061,20 @@ log_clock (const char *string)
if (!initial)
initial = now;
log_debug ("[%6llu] %s", (now - initial)/1000, string);
snprintf (clockbuf, sizeof clockbuf, "[%6llu] ", (now - initial)/1000);
va_start (arg_ptr, fmt);
do_logv (GPGRT_LOG_DEBUG, 0, NULL, clockbuf, fmt, arg_ptr);
va_end (arg_ptr);
#else /*!ENABLE_LOG_CLOCK*/
/* You may need to link with -ltr to use the above code. */
log_debug ("[not enabled by configure] %s", string);
va_list arg_ptr;
va_start (arg_ptr, fmt);
do_logv (GPGRT_LOG_DEBUG, 0, NULL, "[no clock] ", fmt, arg_ptr);
va_end (arg_ptr);
#endif /*!ENABLE_LOG_CLOCK*/
}

View File

@ -109,7 +109,7 @@ void log_flush (void);
by the hexdump and a final LF. */
void log_printhex (const char *text, const void *buffer, size_t length);
void log_clock (const char *string);
void log_clock (const char *fmt, ...) GPGRT_ATTR_PRINTF(1,2);
#endif /*GNUPG_COMMON_LOGGING_H*/