-
Notifications
You must be signed in to change notification settings - Fork 1
/
logger.c
66 lines (53 loc) · 1.37 KB
/
logger.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
* Name : logger.c
* Project : Allen temporal logic: seminar schedule verifier
* Author : David Hildenbrand, Tobias Schoknecht
* Copyright : David Hildenbrand, Tobias Schoknecht 2012
* ----------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 42):
* [email protected] and [email protected] wrote this file.
* As long as you retain this notice you can do whatever you want with this
* stuff. If we meet some day, and you think this stuff is worth it, you can
* buy us a beer in return David Hildenbrand, Tobias Schoknecht
* ----------------------------------------------------------------------------
*/
#include "logger.h"
#include <stdio.h>
#include <stdarg.h>
void log(enum log_level level, char* format, ...) {
va_list args;
va_start(args, format);
char* type = NULL;
switch (level) {
case INFO:
type = "INFO";
break;
case WARN:
type = "WARNING";
break;
case ERROR:
type = "ERROR";
break;
default:
type = "UNKNOWN";
break;
}
FILE *out = stdout;
if (level == ERROR) {
out = stderr;
}
fprintf(out, "%s\t: ", type);
vfprintf(out, format, args);
fprintf(out, "\n");
fflush(out);
va_end(args);
}
void log_filled_line(char del) {
char buffer[51];
int i;
for (i = 0; i < 50; ++i) {
buffer[i] = del;
}
buffer[50] = '\0';
log(INFO, "%s", buffer);
}