-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlog.c
More file actions
74 lines (69 loc) · 1.82 KB
/
log.c
File metadata and controls
74 lines (69 loc) · 1.82 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
71
72
73
74
/*
* log.c
*
* Created on: Mar 13, 2014
* Author: Michael
*/
#include "subsys.h"
#include "buffer_printf.h"
#define LogChar(c) Push(LOG_BUF,c)
void LogHeader(enum sys_index sys, enum priority_level level);
void LogStr(char * str, ...) {
// variable argument list type
va_list vars;
// initialize the variable argument list pointer by specifying the
// input argument immediately preceding the variable list
va_start(vars, str);
// use Push_vprintf to log to LOG_BUF
Push_vprintf(LOG_BUF, str, vars);
va_end(vars);
}
void LogMsg(enum sys_index sys, enum priority_level lev, char * str, ...) {
// variable argument list type
va_list vars;
if (GetSubsystemPriority(sys) >= lev) {
// output header
LogHeader(sys, lev);
// initialize the variable argument list pointer by specifying the
// input argument immediately preceding the variable list
va_start(vars, str);
// use Push_vprintf to log to LOG_BUF
Push_vprintf(LOG_BUF, str, vars);
va_end(vars);
// new line
LogChar('\r');
LogChar('\n');
}
}
void LogHeader(enum sys_index sys, enum priority_level level) {
char * ptr;
// output timestamp
#ifdef LOG_FORMAT_TIMESTAMP
timestruct_t t;
t = TimeNowF();
Push_uint16(LOG_BUF, t.hr);
LogChar(':');
if(t.min < 10) LogChar('0');
Push_uint16(LOG_BUF, t.min);
LogChar(':');
if(t.sec < 10) LogChar('0');
Push_uint16(LOG_BUF, t.sec);
LogChar('.');
if(t.ms < 100) LogChar('0');
if(t.ms < 10) LogChar('0');
Push_uint16(LOG_BUF, t.ms);
#else
Push_uint32(LOG_BUF,GetLogTimestamp());
#endif
LogChar('_');
ptr = GetSubsystemName(sys);
while (*ptr != 0) {
LogChar(*ptr++);
}
LogChar('_');
ptr = GetPriorityLevelName(level);
while (*ptr != 0) {
LogChar(*ptr++);
}
LogChar(' ');
}