summaryrefslogtreecommitdiff
path: root/lib/tdb2/test/tdb1-logging.c
blob: 43ce07b27cc3bb46a0762fb5ad382f9a4c4b67aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include "tdb1-logging.h"
#include <ccan/tap/tap.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

/* Turn log messages into tap diag messages. */
static void taplog(struct tdb1_context *tdb,
		   enum tdb1_debug_level level,
		   const char *fmt, ...)
{
	va_list ap;
	char line[200];

	if (suppress_logging)
		return;

	va_start(ap, fmt);
	vsprintf(line, fmt, ap);
	va_end(ap);

	/* Strip trailing \n: diag adds it. */
	if (line[0] && line[strlen(line)-1] == '\n')
		diag("%s%.*s", log_prefix, (unsigned)strlen(line)-1, line);
	else
		diag("%s%s", log_prefix, line);
}

struct tdb1_logging_context taplogctx = { taplog, NULL };