summaryrefslogtreecommitdiffstats
path: root/util/stream/debug.h
diff options
context:
space:
mode:
authorDevtools Arcadia <[email protected]>2022-02-07 18:08:42 +0300
committerDevtools Arcadia <[email protected]>2022-02-07 18:08:42 +0300
commit1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch)
treee26c9fed0de5d9873cce7e00bc214573dc2195b7 /util/stream/debug.h
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'util/stream/debug.h')
-rw-r--r--util/stream/debug.h53
1 files changed, 53 insertions, 0 deletions
diff --git a/util/stream/debug.h b/util/stream/debug.h
new file mode 100644
index 00000000000..92d6d4b42da
--- /dev/null
+++ b/util/stream/debug.h
@@ -0,0 +1,53 @@
+#pragma once
+
+#include "output.h"
+
+/**
+ * @addtogroup Streams
+ * @{
+ */
+
+/**
+ * Debug output stream. Writes into `stderr`.
+ */
+class TDebugOutput: public IOutputStream {
+public:
+ inline TDebugOutput() noexcept = default;
+ ~TDebugOutput() override = default;
+
+ TDebugOutput(TDebugOutput&&) noexcept = default;
+ TDebugOutput& operator=(TDebugOutput&&) noexcept = default;
+
+private:
+ void DoWrite(const void* buf, size_t len) override;
+};
+
+/**
+ * @returns Standard debug stream.
+ * @see Cdbg
+ */
+IOutputStream& StdDbgStream() noexcept;
+
+/**
+ * This function returns the current debug level as set via `DBGOUT` environment
+ * variable.
+ *
+ * Note that the proper way to use this function is via `Y_DBGTRACE` macro.
+ * There are very few cases when there is a need to use it directly.
+ *
+ * @returns Debug level.
+ * @see ETraceLevel
+ * @see DBGTRACE
+ */
+int StdDbgLevel() noexcept;
+
+/**
+ * Standard debug stream.
+ *
+ * Behavior of this stream is controlled via `DBGOUT` environment variable.
+ * If this variable is set, then this stream is redirected into `stderr`,
+ * otherwise whatever is written into it is simply ignored.
+ */
+#define Cdbg (StdDbgStream())
+
+/** @} */