blob: 62749610144572166cbe50601079bf23f1f8139b [file] [log] [blame]
Miroslav Zagorac70230c62020-12-09 16:54:31 +01001/***
2 * Copyright 2020 HAProxy Technologies
3 *
4 * This file is part of the HAProxy OpenTracing filter.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 */
20#ifndef _OPENTRACING_DEBUG_H_
21#define _OPENTRACING_DEBUG_H_
22
23#ifdef DEBUG_FULL
24# define DEBUG_OT
25#endif
26
27#ifdef DEBUG_OT
28# ifdef DEBUG_OT_SYSTIME
29# define FLT_OT_DBG_FMT(f) "[% 2d] %ld.%06ld [" FLT_OT_SCOPE "]: " f, tid, now.tv_sec, now.tv_usec
30# else
31# define FLT_OT_DBG_FMT(f) "[% 2d] %11.6f [" FLT_OT_SCOPE "]: " f, tid, FLT_OT_TV_UDIFF(&(flt_ot_debug.start), &now) / 1e6
32# endif
33# define FLT_OT_DBG_INDENT " "
34# define FLT_OT_DBG(l,f, ...) \
35 do { \
36 if (!(l) || (flt_ot_debug.level & (1 << (l)))) \
37 (void)fprintf(stderr, FLT_OT_DBG_FMT("%.*s" f "\n"), \
38 dbg_indent_level, FLT_OT_DBG_INDENT, ##__VA_ARGS__); \
39 } while (0)
40# define FLT_OT_FUNC(f, ...) do { FLT_OT_DBG(1, "%s(" f ") {", __func__, ##__VA_ARGS__); dbg_indent_level += 3; } while (0)
41# define FLT_OT_RETURN(a) do { dbg_indent_level -= 3; FLT_OT_DBG(1, "}"); return a; } while (0)
Miroslav Zagoracca09e012022-03-04 09:56:00 +010042# define FLT_OT_RETURN_EX(a,t,f) do { dbg_indent_level -= 3; { t _r = (a); FLT_OT_DBG(1, "} = " f, _r); return _r; } } while (0)
43# define FLT_OT_RETURN_INT(a) FLT_OT_RETURN_EX((a), int, "%d")
44# define FLT_OT_RETURN_PTR(a) FLT_OT_RETURN_EX((a), void *, "%p")
Miroslav Zagorac70230c62020-12-09 16:54:31 +010045# define FLT_OT_DBG_IFDEF(a,b) a
46# define FLT_OT_DBG_ARGS(a, ...) a, ##__VA_ARGS__
Miroslav Zagorac52c2ec32022-03-10 00:03:24 +010047# define FLT_OT_DBG_BUF(a,b) do { FLT_OT_DBG((a), "%p:{ %zu %p %zu %zu }", (b), (b)->size, (b)->area, (b)->data, (b)->head); } while (0)
Miroslav Zagorac70230c62020-12-09 16:54:31 +010048
49struct flt_ot_debug {
50#ifndef DEBUG_OT_SYSTIME
51 struct timeval start;
52#endif
53 uint8_t level;
54};
55
56
57extern THREAD_LOCAL int dbg_indent_level;
58extern struct flt_ot_debug flt_ot_debug;
59
60#else
61
62# define FLT_OT_DBG(...) while (0)
63# define FLT_OT_FUNC(...) while (0)
64# define FLT_OT_RETURN(a) return a
Miroslav Zagoracca09e012022-03-04 09:56:00 +010065# define FLT_OT_RETURN_EX(a,t,f) return a
66# define FLT_OT_RETURN_INT(a) return a
67# define FLT_OT_RETURN_PTR(a) return a
Miroslav Zagorac70230c62020-12-09 16:54:31 +010068# define FLT_OT_DBG_IFDEF(a,b) b
69# define FLT_OT_DBG_ARGS(...)
Miroslav Zagoracca09e012022-03-04 09:56:00 +010070# define FLT_OT_DBG_BUF(a,b) while (0)
Miroslav Zagorac70230c62020-12-09 16:54:31 +010071#endif /* DEBUG_OT */
72
73/*
74 * ON | NOLOGNORM |
75 * -----+-----------+-------------
76 * 0 | 0 | no log
77 * 0 | 1 | no log
78 * 1 | 0 | log all
79 * 1 | 1 | log errors
80 * -----+-----------+-------------
81 */
82#define FLT_OT_LOG(l,f, ...) \
83 do { \
84 if (!(conf->tracer->logging & FLT_OT_LOGGING_ON)) \
85 FLT_OT_DBG(3, "NOLOG[%d]: [" FLT_OT_SCOPE "]: [%s] " f, (l), conf->id, ##__VA_ARGS__); \
86 else if ((conf->tracer->logging & FLT_OT_LOGGING_NOLOGNORM) && ((l) > LOG_ERR)) \
87 FLT_OT_DBG(2, "NOLOG[%d]: [" FLT_OT_SCOPE "]: [%s] " f, (l), conf->id, ##__VA_ARGS__); \
88 else { \
89 send_log(&(conf->tracer->proxy_log), (l), "[" FLT_OT_SCOPE "]: [%s] " f "\n", conf->id, ##__VA_ARGS__); \
90 \
91 FLT_OT_DBG(1, "LOG[%d]: %s", (l), logline); \
92 } \
93 } while (0)
94
95#endif /* _OPENTRACING_DEBUG_H_ */
96
97/*
98 * Local variables:
99 * c-indent-level: 8
100 * c-basic-offset: 8
101 * End:
102 *
103 * vi: noexpandtab shiftwidth=8 tabstop=8
104 */