]> git.ozlabs.org Git - ccan/blob - ccan/tdb2/test/logging.c
tdb2: test: import tdb1's tests.
[ccan] / ccan / tdb2 / test / logging.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <ccan/tap/tap.h>
4 #include "logging.h"
5
6 unsigned tap_log_messages;
7 const char *log_prefix = "";
8 char *log_last = NULL;
9 bool suppress_logging;
10
11 union tdb_attribute tap_log_attr = {
12         .log = { .base = { .attr = TDB_ATTRIBUTE_LOG },
13                  .fn = tap_log_fn }
14 };
15
16 void tap_log_fn(struct tdb_context *tdb,
17                 enum tdb_log_level level,
18                 enum TDB_ERROR ecode,
19                 const char *message, void *priv)
20 {
21         if (suppress_logging)
22                 return;
23
24         diag("tdb log level %u: %s: %s%s",
25              level, tdb_errorstr(ecode), log_prefix, message);
26         if (log_last)
27                 free(log_last);
28         log_last = strdup(message);
29         tap_log_messages++;
30 }
31