aboutsummaryrefslogtreecommitdiffstats
path: root/trace.c
blob: d8e6ef2378c8c3cd0cbe41e6ac9e26578c09b370 (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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
 * Copyright (C) 2020  Tomasz Kramkowski <tk@the-tk.com>
 * SPDX-License-Identifier: MIT
 */
#include <stdarg.h>
#include <stdio.h>

#include "pack.h"
#include "trace.h"

enum pack_trace pack_trace = PACK_TRACE_OFF;

ATTRIBUTE_FORMAT(printf, 2, 0)
static void trace(enum pack_trace level, const char *fmt, va_list va)
{
	char *type;

	if (level > pack_trace) return;

	switch (level) {
	case PACK_TRACE_CALL: type = "CALL"; break;
	case PACK_TRACE_DEBUG: type = "DEBUG"; break;
	default: type = "???"; break;
	}

	fprintf(stderr, "PACK_TRACE_%s: ", type);
	vfprintf(stderr, fmt, va);
	fputc('\n', stderr);
}

void tr_call(const char *fmt, ...)
{
	va_list va;

	va_start(va, fmt);
	trace(PACK_TRACE_CALL, fmt, va);
	va_end(va);
}

void tr_debug(const char *fmt, ...)
{
	va_list va;

	va_start(va, fmt);
	trace(PACK_TRACE_DEBUG, fmt, va);
	va_end(va);
}