X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Ftdb2%2Ftest%2Flogging.c;h=85bdc064c80a7fe179f848e789dc62d1806f2d15;hb=ec88af5dd11a003beb8cd3fbe420f9d5e5dcf5d9;hp=8b057bc662786f5b68761765480ded80da32cb2d;hpb=06e0037d97f5e1d83667ec40627cef862f3b7b85;p=ccan diff --git a/ccan/tdb2/test/logging.c b/ccan/tdb2/test/logging.c index 8b057bc6..85bdc064 100644 --- a/ccan/tdb2/test/logging.c +++ b/ccan/tdb2/test/logging.c @@ -6,6 +6,13 @@ #include "logging.h" unsigned tap_log_messages; +const char *log_prefix = ""; +bool suppress_logging; + +union tdb_attribute tap_log_attr = { + .log = { .base = { .attr = TDB_ATTRIBUTE_LOG }, + .log_fn = tap_log_fn } +}; void tap_log_fn(struct tdb_context *tdb, enum tdb_debug_level level, void *priv, @@ -14,12 +21,19 @@ void tap_log_fn(struct tdb_context *tdb, va_list ap; char *p; + if (suppress_logging) + return; + va_start(ap, fmt); if (vasprintf(&p, fmt, ap) == -1) abort(); - diag("tdb log level %u: %s", level, p); + /* Strip trailing \n: diag adds it. */ + if (p[strlen(p)-1] == '\n') + p[strlen(p)-1] = '\0'; + diag("tdb log level %u: %s%s", level, log_prefix, p); free(p); - tap_log_messages++; + if (level != TDB_DEBUG_TRACE) + tap_log_messages++; va_end(ap); }