-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog.c
59 lines (52 loc) · 1.28 KB
/
log.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
#include "log.h"
#include "fb.h"
#include "serial.h"
#include "string.h"
#ifdef LOG_TO_SCREEN
void (*log_puts)(const char*) = &fb_puts;
#else
void (*log_puts)(const char*) = &serial_puts;
#endif
void log_message_no_newline(int level, const char* filename, int line,
const char* text) {
switch (level) {
case INFO:
log_puts("INFO:");
break;
case WARNING:
log_puts("WARNING:");
break;
case ERROR:
log_puts("ERROR:");
break;
default:
log_puts("UNKNOWN:");
}
log_puts(filename);
log_puts(":");
char dec_str[12];
int_to_dec(line, dec_str);
log_puts(dec_str);
log_puts(":");
log_puts(text);
}
void log_message(int level, const char* filename, int line, const char* text) {
log_message_no_newline(level, filename, line, text);
log_puts("\n");
}
void log_int(int level, const char* filename, int line, const char* text,
int i) {
char dec[12];
int_to_dec(i, dec);
log_message_no_newline(level, filename, line, text);
log_puts(dec);
log_puts("\n");
}
void log_hex(int level, const char* filename, int line, const char* text,
unsigned int i) {
char hex[12];
int_to_hex(i, hex);
log_message_no_newline(level, filename, line, text);
log_puts(hex);
log_puts("\n");
}