-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathddebug.c
More file actions
96 lines (81 loc) · 1.96 KB
/
ddebug.c
File metadata and controls
96 lines (81 loc) · 1.96 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// #include <time.h>
#include "derp.h"
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef DLOG_COLORS
#define RESET "\x1b[0m"
static const char* dlog_colours[DLOG_NUMBER] = {
#define DLOG(e, s, c) c,
DLOG_LEVEL_DATA
#undef DLOG
};
#endif
void dlog_func(DLogLevel log_level, const char* file, int line, const char* fmt, ...);
// string version of log levels
const char* log_strings[DLOG_NUMBER] = {
#define DLOG(e, s, c) s,
DLOG_LEVEL_DATA
#undef DLOG
};
void assert_fail (const char* expr, const char* file, int line, const char * fmt, ...) {
char string[1024] = { 0 };
va_list va;
va_start(va, fmt);
vsnprintf((char*)string, 1024, fmt, va);
va_end(va);
# ifdef DLOG_COLORS
printf("%s[ASSERT FAIL]:%s {%s} at (%s:%i)\n [msg]: %s\n"
, dlog_colours[1]
, RESET
, expr
, file
, line
, (char*) string
);
# else
printf("[ASSERT FAIL]: {%s} at (%s:%i)\n [msg]: %s\n"
, expr
, file
, line
, (char*) string
);
# endif
abort();
}
void dlog_init(DLogLevel lvl) {
def_logger.level = lvl;
def_logger.f_out = stdout;
}
void dlog_func ( DLogLevel log_level, const char* file, int line, const char* fmt, ...) {
dassert(def_logger.level > 0,
"Invalid default logging level set [%i]\n\t > make sure to run dlog_init() before using the logging functions!", def_logger.level);
if (log_level > def_logger.level) {
return;
}
char* string[32000];
memset(string, 0, sizeof(string));
va_list va;
va_start(va, fmt);
vsnprintf((char*)string, 32000, fmt, va);
va_end(va);
char* out_string[32000];
memset(out_string, 0, sizeof(out_string));
# ifdef DLOG_COLORS
sprintf((char*)out_string, "%s[%s] \x1b[90m%s:%i%s, %s\n",
dlog_colours[log_level],
log_strings[log_level],
file,
line,
RESET,
(char*)string);
# else
sprintf((char*)out_string, "[%s] %s:%i, %s\n",
log_strings[log_level],
file,
line,
(char*)string);
# endif
fprintf(def_logger.f_out, "%s", (char*)out_string);
}