From 2412048fc02d00341f735e2b4e3a6b2ccb17a6b8 Mon Sep 17 00:00:00 2001 From: Jari Vetoniemi Date: Thu, 1 Nov 2018 03:51:09 +0200 Subject: hide all logging under ASOUND_DEBUG env variable --- src/util/util.h | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/util/util.h b/src/util/util.h index 9e118c2..67c47e0 100644 --- a/src/util/util.h +++ b/src/util/util.h @@ -5,10 +5,21 @@ #include #include -#define WARN1(x) do { warn("asound: %s %s", __func__, x); } while (0) -#define WARN(x, ...) do { warn("asound: %s " x, __func__, ##__VA_ARGS__); } while (0) -#define WARNX1(x) do { warnx("asound: %s %s", __func__, x); } while (0) -#define WARNX(x, ...) do { warnx("asound: %s " x, __func__, ##__VA_ARGS__); } while (0) +static inline int +do_debug(void) +{ + static int debug = -1; + if (debug == -1) { + const char *env = getenv("ASOUND_DEBUG"); + debug = (env && !!strcmp(env, "0")); + } + return debug; +} + +#define WARN1(x) do { if (do_debug()) warn("asound: %s %s", __func__, x); } while(0) +#define WARN(x, ...) do { if (do_debug()) warn("asound: %s " x, __func__, ##__VA_ARGS__); } while (0) +#define WARNX1(x) do { if (do_debug()) warnx("asound: %s %s", __func__, x); } while (0) +#define WARNX(x, ...) do { if (do_debug()) warnx("asound: %s " x, __func__, ##__VA_ARGS__); } while (0) #define ERRX1(x, y) do { errx(x, "asound: %s %s", __func__, y); } while (0) #define ERRX(x, y, ...) do { errx(x, "asound: %s " y, __func__, ##__VA_ARGS__); } while (0) #define ERR(x, y, ...) do { err(x, "asound: %s " y, __func__, ##__VA_ARGS__); } while (0) -- cgit v1.2.3