summaryrefslogtreecommitdiff
path: root/lib/tdb2/test/tdb1-logging.c
blob: 3424296b9184ffeb73f0128d9c7b43f950c04999 (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
#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 tdb_log_level level,
		   enum TDB_ERROR ecode,
		   const char *message,
		   void *data)
{
	if (suppress_logging)
		return;

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

struct tdb1_logging_context taplogctx = { taplog, NULL };