-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug.c
More file actions
45 lines (36 loc) · 727 Bytes
/
Copy pathdebug.c
File metadata and controls
45 lines (36 loc) · 727 Bytes
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
#include <stdio.h>
#include <sys/time.h>
#include "debug.h"
static const char * const log_level_names[] = {
"ERR",
"WARN",
"NOTICE",
"INFO",
"DEBUG",
};
int log_level = DSD_ERR;
void dsd_time_in_microseconds(int n)
{
unsigned long long now;
struct timeval tv;
gettimeofday(&tv, NULL);
now = ((unsigned long long)tv.tv_sec * 1000000LL) + tv.tv_usec;
fprintf(stderr, "%s:[%llu:%d]", log_level_names[n], now / 1000000, (int)(now % 1000000));
}
void dsd_set_log_level(int level)
{
log_level = level;
}
int dsd_log_filter(int filter)
{
int i = 0;
if (log_level & filter) {
for (i = 0; i < DSD_COUNT; i++) {
if (filter == (1 << i)) {
dsd_time_in_microseconds(i);
return 1;
}
}
}
return 0;
}