-
Notifications
You must be signed in to change notification settings - Fork 1
/
pd_log.c
executable file
·50 lines (43 loc) · 1003 Bytes
/
pd_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
#include "pd_log.h"
static int *pd_log_glevel()
{
static int glevel = INFO;
return &glevel;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
const char* pd_log_print_array(char* buf, int64_t len, int64_t* array, int size)
{
int64_t pos = 0;
int64_t count = 0;
int64_t i = 0;
for(i = 0; i < size; i++)
{
count = snprintf(buf + pos, len - pos, "0x%lx ", array[i]);
if (count >= 0 && pos + count + 1 < len)
{
pos += count;
}
else
{
PD_LOG(WARN, "buf not enough, len=%ld, array_size=%d", len, size);
break;
}
}
buf[pos + 1] = 0;
return buf;
}
const char* pd_log_print_bt()
{
static __thread void *addrs[100];
static __thread char buf[1024];
int size = backtrace(addrs, 100);
return pd_log_print_array(buf, sizeof(buf), (int64_t*)addrs, size);
}
void pd_log_set_glevel(const int level)
{
*pd_log_glevel() = level;
}
int pd_log_get_glevel()
{
return *pd_log_glevel();
}