util  def.c at [e02ae59ffd]

File wgsync/src/def.c artifact 1b046527ed part of check-in e02ae59ffd


#include "def.h"
#include <stdio.h>
#include <unistd.h>

uint8_t g_loglevel =
#ifdef _cfg_debug
	4
#else
	3
#endif
;

char thread_local g_logbuf [sizeof g_logbuf];

void msg
(	uint8_t level,
	char*   tag,
	uint8_t color,
	char*   msg
) {
	if(level > g_loglevel) return;
	if(isatty(fileno(stderr))) {
		fprintf(stderr, "\x1b[1;3%cm(%s)\x1b[m %s\n",
				0x30 + color, tag, msg);
	} else {
		fprintf(stderr, "(%s) %s\n", tag, msg);
	}
}