aboutsummaryrefslogtreecommitdiffstats
path: root/util/stream/debug.h
blob: 86601ea0ba7024bb22a264e32522973877bdba16 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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())

/** @} */