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