summaryrefslogtreecommitdiffstats
path: root/src/log.c
blob: 81a1c0bd16f9f712b2e0ece7a07dfe0612536d2f (plain) (blame)
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "log.h"
#include "util.h"

#include <stdbool.h>
#include <stdlib.h>

static int log_active;
static FILE *log_file;

void
log_init(void)
{
	const char *envstr;

	log_active = false;

	envstr = getenv("TMUS_LOG");
	if (!envstr) return;

	log_file = fopen(envstr, "w+");
	if (!log_file) ERROR(SYSTEM, "fopen %s", envstr);

	log_active = true;
}

void
log_deinit(void)
{
	if (!log_active) return;

	fclose(log_file);
	log_active = 0;
}

void
log_info(const char *fmtstr, ...)
{
	va_list ap;

	if (!log_active) return;

	va_start(ap, fmtstr);
	vfprintf(log_file, fmtstr, ap);
	va_end(ap);

	fflush(log_file);
}

void
log_infov(const char *fmtstr, va_list ap)
{
	if (!log_active) return;

	vfprintf(log_file, fmtstr, ap);

	fflush(log_file);
}