diff options
Diffstat (limited to 'common/logging.c')
-rw-r--r-- | common/logging.c | 40 |
1 files changed, 29 insertions, 11 deletions
diff --git a/common/logging.c b/common/logging.c index c4eaca411..88860e715 100644 --- a/common/logging.c +++ b/common/logging.c @@ -63,6 +63,10 @@ #include "logging.h" #include "sysutils.h" +#if defined(GPGRT_ENABLE_LOG_MACROS) && defined(log_debug_string) + /* Nothing to do; the libgpgrt functions are used. */ +#else /* Use our own logging functions. */ + #ifdef HAVE_W32_SYSTEM # ifndef S_IRWXG # define S_IRGRP S_IRUSR @@ -885,7 +889,7 @@ log_logv (int level, const char *fmt, va_list arg_ptr) * Note that PREFIX is an additional string and independent of the * prefix set by log_set_prefix. */ void -log_logv_with_prefix (int level, const char *prefix, +log_logv_prefix (int level, const char *prefix, const char *fmt, va_list arg_ptr) { do_logv (level, 0, NULL, prefix, fmt, arg_ptr); @@ -977,7 +981,7 @@ log_debug (const char *fmt, ...) * printed with LFs expanded to include the prefix and a final --end-- * marker. */ void -log_debug_with_string (const char *string, const char *fmt, ...) +log_debug_string (const char *string, const char *fmt, ...) { va_list arg_ptr ; @@ -1011,7 +1015,7 @@ log_flush (void) dump, with TEXT just an empty string, print a trailing linefeed, otherwise print an entire debug line. */ void -log_printhex (const char *text, const void *buffer, size_t length) +log_printhex (const void *buffer, size_t length, const char *text) { if (text && *text) log_debug ("%s ", text); @@ -1039,14 +1043,16 @@ log_printsexp () {} is found in sexputils.c */ - +/* Print a microsecond timestamp followed by a FORMAT. */ void -log_clock (const char *string) +log_clock (const char *fmt, ...) { -#if 0 +#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,11 +1065,21 @@ log_clock (const char *string) if (!initial) initial = now; - log_debug ("[%6llu] %s", (now - initial)/1000, string); -#else - /* You need to link with -ltr to enable the above code. */ - log_debug ("[not enabled in the source] %s", string); -#endif + 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. */ + 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*/ } @@ -1101,3 +1117,5 @@ _log_assert (const char *expr, const char *file, int line) abort (); /* Never called; just to make the compiler happy. */ } #endif /*!GPGRT_HAVE_MACRO_FUNCTION*/ + +#endif /* Use our own logging functions. */ |