forked from uart/hardwarePrefetching
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog.c
54 lines (41 loc) · 973 Bytes
/
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
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <time.h>
#include "log.h"
static int runtime_loglevel = 5;
int log_setlevel(int level)
{
if(level > 5 || level < 1)return 0;
runtime_loglevel = level;
return level;
}
char * mergetags(char *t, char *f, int l)
{
static char taggbuff[180];
sprintf(taggbuff, "%s %s+%d", t, f, l);
return taggbuff;
}
int loglevel(int level, char *tag, const char * format, ...)
{
if(level > runtime_loglevel)return 0;
time_t now = time(NULL);
char * timestr = ctime(&now);
timestr[strlen(timestr)-1] = '\0'; //remove newline
printf("%d %s %s|", level, timestr, tag);
va_list args;
va_start (args, format);
int r = vprintf (format, args);
va_end (args);
return r;
}
/*
#define TAG "TEST"
int main()
{
// loglevel(1, TAG, "your usual message\n");
// loglevel(2, TAG, "Testing numbers %d %f\n", 1,0.2);
loga(TAG, "Testing numbers %d %f\n", 1,0.2);
logd(TAG, "Debugtest %d\n", 1);
return 0;
}*/