-
Notifications
You must be signed in to change notification settings - Fork 9
/
debug_print.cpp
55 lines (47 loc) · 997 Bytes
/
debug_print.cpp
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
#include <stdio.h>
#include <stdarg.h>
#include "common.h"
#include "debug_print.h"
#include "error.h"
extern config_t config;
static int __call_depth = 0;
static int indent_char;
LogScope::LogScope() {
if (config.log) {
++__call_depth;
}
}
LogScope::~LogScope() {
if (config.log) {
--__call_depth;
}
}
void print_indentation() {
if (config.log) {
if (__call_depth > 0) {
for (int i = 0; i != __call_depth - 1; ++i)
printf("%c ", indent_char);
}
}
}
void debug_print(const char *fmt, ...) {
if (config.log) {
va_list args;
va_start(args, fmt);
print_indentation();
vprintf(fmt, args);
va_end(args);
}
}
void debug_line(const char *fmt, ...) {
if (config.log) {
va_list args;
va_start(args, fmt);
debug_print(fmt, args);
printf("\n");
va_end(args);
}
}
void set_indent_char(int c) {
indent_char = c;
}