forked from badlogic/ghostling
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug.c
More file actions
39 lines (33 loc) · 762 Bytes
/
debug.c
File metadata and controls
39 lines (33 loc) · 762 Bytes
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
#include "debug.h"
#include <stdarg.h>
#include <stdio.h>
#include <time.h>
static const char *debug_log_path = "ghostling-debug.log";
void debug_log_reset(void)
{
FILE *f = fopen(debug_log_path, "w");
if (!f)
return;
fputs("ghostling debug log\n", f);
fclose(f);
}
void debug_log(const char *fmt, ...)
{
FILE *f = fopen(debug_log_path, "a");
if (!f)
return;
time_t now = time(NULL);
struct tm tm_now;
#if defined(_WIN32)
localtime_s(&tm_now, &now);
#else
localtime_r(&now, &tm_now);
#endif
fprintf(f, "[%02d:%02d:%02d] ", tm_now.tm_hour, tm_now.tm_min, tm_now.tm_sec);
va_list args;
va_start(args, fmt);
vfprintf(f, fmt, args);
va_end(args);
fputc('\n', f);
fclose(f);
}