blob: 7becdf72f1c8ca41758aa1d354f08cecdda99d30 [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)
42# define FLT_OT_DBG_IFDEF(a,b) a
43# define FLT_OT_DBG_ARGS(a, ...) a, ##__VA_ARGS__
44
45struct flt_ot_debug {
46#ifndef DEBUG_OT_SYSTIME
47 struct timeval start;
48#endif
49 uint8_t level;
50};
51
52
53extern THREAD_LOCAL int dbg_indent_level;
54extern struct flt_ot_debug flt_ot_debug;
55
56#else
57
58# define FLT_OT_DBG(...) while (0)
59# define FLT_OT_FUNC(...) while (0)
60# define FLT_OT_RETURN(a) return a
61# define FLT_OT_DBG_IFDEF(a,b) b
62# define FLT_OT_DBG_ARGS(...)
63#endif /* DEBUG_OT */
64
65/*
66 * ON | NOLOGNORM |
67 * -----+-----------+-------------
68 * 0 | 0 | no log
69 * 0 | 1 | no log
70 * 1 | 0 | log all
71 * 1 | 1 | log errors
72 * -----+-----------+-------------
73 */
74#define FLT_OT_LOG(l,f, ...) \
75 do { \
76 if (!(conf->tracer->logging & FLT_OT_LOGGING_ON)) \
77 FLT_OT_DBG(3, "NOLOG[%d]: [" FLT_OT_SCOPE "]: [%s] " f, (l), conf->id, ##__VA_ARGS__); \
78 else if ((conf->tracer->logging & FLT_OT_LOGGING_NOLOGNORM) && ((l) > LOG_ERR)) \
79 FLT_OT_DBG(2, "NOLOG[%d]: [" FLT_OT_SCOPE "]: [%s] " f, (l), conf->id, ##__VA_ARGS__); \
80 else { \
81 send_log(&(conf->tracer->proxy_log), (l), "[" FLT_OT_SCOPE "]: [%s] " f "\n", conf->id, ##__VA_ARGS__); \
82 \
83 FLT_OT_DBG(1, "LOG[%d]: %s", (l), logline); \
84 } \
85 } while (0)
86
87#endif /* _OPENTRACING_DEBUG_H_ */
88
89/*
90 * Local variables:
91 * c-indent-level: 8
92 * c-basic-offset: 8
93 * End:
94 *
95 * vi: noexpandtab shiftwidth=8 tabstop=8
96 */