debug.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #pragma once
  2. #include "output.h"
  3. /**
  4. * @addtogroup Streams
  5. * @{
  6. */
  7. /**
  8. * Debug output stream. Writes into `stderr`.
  9. */
  10. class TDebugOutput: public IOutputStream {
  11. public:
  12. inline TDebugOutput() noexcept = default;
  13. ~TDebugOutput() override = default;
  14. TDebugOutput(TDebugOutput&&) noexcept = default;
  15. TDebugOutput& operator=(TDebugOutput&&) noexcept = default;
  16. private:
  17. void DoWrite(const void* buf, size_t len) override;
  18. };
  19. /**
  20. * @returns Standard debug stream.
  21. * @see Cdbg
  22. */
  23. IOutputStream& StdDbgStream() noexcept;
  24. /**
  25. * This function returns the current debug level as set via `DBGOUT` environment
  26. * variable.
  27. *
  28. * Note that the proper way to use this function is via `Y_DBGTRACE` macro.
  29. * There are very few cases when there is a need to use it directly.
  30. *
  31. * @returns Debug level.
  32. * @see ETraceLevel
  33. * @see DBGTRACE
  34. */
  35. int StdDbgLevel() noexcept;
  36. /**
  37. * Standard debug stream.
  38. *
  39. * Behavior of this stream is controlled via `DBGOUT` environment variable.
  40. * If this variable is set, then this stream is redirected into `stderr`,
  41. * otherwise whatever is written into it is simply ignored.
  42. */
  43. #define Cdbg (StdDbgStream())
  44. /** @} */