-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.c
41 lines (37 loc) · 904 Bytes
/
utils.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
#include "libtex.h"
#include <stdarg.h>
#include <stdio.h>
TMLogLevel TMLogGlobalLevel;
void TMLogSetLevel(TMLogLevel i) {
if ((i < 0) || (i > TMLogLevelAll)) {
TMLogError("Invalid log level %d", i);
}
else {
TMLogGlobalLevel = i;
}
}
void TMLog(TMLogLevel level, char *file, unsigned long line, char *message, ...) {
if (level > TMLogGlobalLevel)
return;
switch (level) {
case TMLogLevelError:
fprintf(stderr, "[%s] %s:%d: ", "ERROR", file, line);
break;
case TMLogLevelWarning:
fprintf(stderr, "[%s] %s:%d: ", "WARNING", file, line);
break;
case TMLogLevelInfo:
fprintf(stderr, "[%s] %s:%d: ", "INFO", file, line);
break;
case TMLogLevelDebug:
fprintf(stderr, "[%s] %s:%d: ", "DEBUG", file, line);
break;
default:
return;
}
va_list argptr;
va_start(argptr, message);
vfprintf(stderr, message, argptr);
va_end(argptr);
fprintf(stderr, "\n");
}