aboutsummaryrefslogtreecommitdiffstats
path: root/util/stream/trace.h
diff options
context:
space:
mode:
authorDevtools Arcadia <arcadia-devtools@yandex-team.ru>2022-02-07 18:08:42 +0300
committerDevtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net>2022-02-07 18:08:42 +0300
commit1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch)
treee26c9fed0de5d9873cce7e00bc214573dc2195b7 /util/stream/trace.h
downloadydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'util/stream/trace.h')
-rw-r--r--util/stream/trace.h60
1 files changed, 60 insertions, 0 deletions
diff --git a/util/stream/trace.h b/util/stream/trace.h
new file mode 100644
index 0000000000..e74b6ecf3e
--- /dev/null
+++ b/util/stream/trace.h
@@ -0,0 +1,60 @@
+#pragma once
+
+#include "debug.h"
+
+/**
+ * Debug level, as set via `DBGOUT` environment variable.
+ */
+enum ETraceLevel: ui8 {
+ TRACE_ERR = 1,
+ TRACE_WARN = 2,
+ TRACE_NOTICE = 3,
+ TRACE_INFO = 4,
+ TRACE_DEBUG = 5,
+ TRACE_DETAIL = 6,
+ TRACE_VERBOSE = 7
+};
+
+#if !defined(NDEBUG) && !defined(Y_ENABLE_TRACE)
+ #define Y_ENABLE_TRACE
+#endif
+
+#ifdef Y_ENABLE_TRACE
+
+ /**
+ * Writes the given data into standard debug stream if current debug level set
+ * via `DBGOUT` environment variable permits it.
+ *
+ * Does nothing in release builds unless `Y_ENABLE_TRACE` is defined.
+ *
+ * Example usage:
+ * @code
+ * Y_DBGTRACE(DEBUG, "Advance from " << node1 << " to " << node2);
+ * @endcode
+ *
+ * @param elevel Debug level of this trace command, e.g.
+ * `WARN` or `DEBUG`. Basically a suffix of
+ * one of the values of `ETraceLevel` enum.
+ * @param args Argument chain to be written out into
+ * standard debug stream, joined with `<<`
+ * operator.
+ * @see ETraceLevel
+ */
+ #define Y_DBGTRACE(elevel, args) Y_DBGTRACE0(int(TRACE_##elevel), args)
+ #define Y_DBGTRACE0(level, args) \
+ do \
+ if ((level) <= StdDbgLevel()) { \
+ StdDbgStream() << args << Endl; \
+ } \
+ while (false)
+
+#else
+
+ #define Y_DBGTRACE(elevel, args) \
+ do { \
+ } while (false)
+ #define Y_DBGTRACE0(level, args) \
+ do { \
+ } while (false)
+
+#endif