forked from wermipls/pj64-wiiu-gcn
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlog.h
More file actions
70 lines (56 loc) · 1.22 KB
/
Copy pathlog.h
File metadata and controls
70 lines (56 loc) · 1.22 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
#include <stdio.h>
#include <stdarg.h>
#include <time.h>
const char logpath[] = "./Logs/" PLUGIN_NAME ".txt";
FILE *logfile;
void log_open()
{
CreateDirectory("Logs", NULL);
logfile = fopen(logpath, "w");
}
void log_close()
{
fclose(logfile);
}
const char prefix_warn[] = "warning: ";
const char prefix_error[] = "error: ";
const char prefix_none[] = "";
enum LogLevel
{
LOG_INFO,
LOG_WARN,
LOG_ERR,
LOG_ERR_NO_MSGBOX,
};
void dlog(enum LogLevel l, char fmt[], ...)
{
time_t rawtime;
time(&rawtime);
struct tm *timeinfo = localtime(&rawtime);
char timestr[16];
strftime(timestr, sizeof(timestr), "%H:%M:%S", timeinfo);
const char *prefix;
switch (l)
{
case LOG_ERR:
case LOG_ERR_NO_MSGBOX:
prefix = prefix_error;
break;
case LOG_WARN:
prefix = prefix_warn;
break;
default:
prefix = prefix_none;
break;
}
va_list argv;
va_start(argv, fmt);
char msg[1024];
vsnprintf(msg, 1024, fmt, argv);
va_end(argv);
// print to file
fprintf(logfile, "[%s] %s%s\n", timestr, prefix, msg);
if(l == LOG_ERR) {
MessageBox(NULL, msg, PLUGIN_NAME " error", MB_OK | MB_ICONERROR);
}
}