1 #include "logging.h"
2 #include "tap-interface.h"
3 #include <stdarg.h>
4 #include <stdlib.h>
5 #include <string.h>
6 #include <stdio.h>
7 
8 bool suppress_logging = false;
9 const char *log_prefix = "";
10 
11 /* Turn log messages into tap diag messages. */
taplog(struct tdb_context * tdb,enum tdb_debug_level level,const char * fmt,...)12 static void taplog(struct tdb_context *tdb,
13 		   enum tdb_debug_level level,
14 		   const char *fmt, ...)
15 {
16 	va_list ap;
17 	char line[200];
18 
19 	if (suppress_logging)
20 		return;
21 
22 	va_start(ap, fmt);
23 	vsprintf(line, fmt, ap);
24 	va_end(ap);
25 
26 	/* Strip trailing \n: diag adds it. */
27 	if (line[0] && line[strlen(line)-1] == '\n')
28 		diag("%s%.*s", log_prefix, (unsigned)strlen(line)-1, line);
29 	else
30 		diag("%s%s", log_prefix, line);
31 }
32 
33 struct tdb_logging_context taplogctx = { taplog, NULL };
34