-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathlogsys.c
44 lines (38 loc) · 845 Bytes
/
logsys.c
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
#include "logsys.h"
#include <stdio.h>
int logLevel = TRACE;
FILE *logfile;
char *levelStr[7] = {
"[ALL]",
"[TRACE]",
"[DEBUG]",
"[INFO]",
"[WARNING]",
"[ERROR]",
"[FATAL]"
};
void log_open(const char *filename) {
logfile = fopen(filename, "w");
if(logfile == NULL) {
log_msgf(ERROR, "Unable to create log \"%s\".\n", filename);
}
}
void log_close() {
if(logfile == NULL) return;
log_msgf(DEBUG, "Closing log file.\n");
fclose(logfile);
}
/*
void log_msg(int level, const char *msg) {
if(logfile == NULL || logLevel > level) return;
fprintf(logfile, "%s %s", levelStr[level], msg);
}
*/
void log_msgf(int level, const char *format, ...) {
if(logfile == NULL || logLevel > level) return;
fprintf(logfile, "%s ", levelStr[level]);
va_list args;
va_start(args, format);
vfprintf(logfile, format, args);
va_end(args);
}