/src/rtpproxy/libre/rtpp_re_dbg.c
Line | Count | Source |
1 | | #include <stdbool.h> |
2 | | #include <stdlib.h> |
3 | | #include <stdint.h> |
4 | | |
5 | | #define DEBUG_MODULE "dbg" |
6 | | #define DEBUG_LEVEL 0 |
7 | | #include "re_dbg.h" |
8 | | #include "re_fmt.h" |
9 | | |
10 | | #include "rtpp_log.h" |
11 | | |
12 | | static int |
13 | 477 | rtpp_re_dbg_level(int re_level) { |
14 | 477 | switch (re_level) { |
15 | 0 | case DBG_EMERG: |
16 | 0 | case DBG_ALERT: |
17 | 0 | case DBG_CRIT: |
18 | 0 | return (RTPP_LOG_CRIT); |
19 | 0 | case DBG_ERR: |
20 | 0 | return (RTPP_LOG_ERR); |
21 | 477 | case DBG_WARNING: |
22 | 477 | return (RTPP_LOG_WARN); |
23 | 0 | case DBG_NOTICE: |
24 | 0 | case DBG_INFO: |
25 | 0 | return (RTPP_LOG_INFO); |
26 | 0 | case DBG_DEBUG: |
27 | 0 | return (RTPP_LOG_DBUG); |
28 | 477 | } |
29 | 0 | abort(); |
30 | 477 | } |
31 | | |
32 | | void |
33 | | dbg_printf(int level, const char *fmt, ...) |
34 | 477 | { |
35 | 477 | char buf[256]; |
36 | 477 | int len; |
37 | 477 | va_list args; |
38 | | |
39 | 477 | level = rtpp_re_dbg_level(level); |
40 | | |
41 | 477 | va_start(args, fmt); |
42 | 477 | len = re_vsnprintf(buf, sizeof(buf), fmt, args); |
43 | 477 | va_end(args); |
44 | 477 | if (len <= 0) |
45 | 0 | abort(); |
46 | 477 | if (buf[len - 1] == '\n') |
47 | 477 | len -= 1; |
48 | 477 | re_dbg_printf(level, buf, len); |
49 | 477 | } |