summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJari Vetoniemi <mailroxas@gmail.com>2018-11-01 03:51:09 +0200
committerJari Vetoniemi <mailroxas@gmail.com>2018-11-01 03:51:09 +0200
commit2412048fc02d00341f735e2b4e3a6b2ccb17a6b8 (patch)
tree3e6b26dcf3f4f82cf39aaa95281d0bbd6dfbaccf
parent923e6f40a3b41b1af91940c6f738523320a1b0d2 (diff)
hide all logging under ASOUND_DEBUG env variable
-rw-r--r--src/util/util.h19
1 files changed, 15 insertions, 4 deletions
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 <stddef.h>
#include <err.h>
-#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)