#include "null.h" #include "debug.h" #include #include #include #include #include void TDebugOutput::DoWrite(const void* buf, size_t len) { if (len != fwrite(buf, 1, len, stderr)) { ythrow yexception() << "write failed(" << LastSystemErrorText() << ")"; } } namespace { struct TDbgSelector { inline TDbgSelector() { char* dbg = getenv("DBGOUT"); if (dbg) { Out = &Cerr; try { Level = FromString(dbg); } catch (const yexception&) { Level = 0; } } else { Out = &Cnull; Level = 0; } } IOutputStream* Out; int Level; }; } template <> struct TSingletonTraits { static constexpr size_t Priority = 8; }; IOutputStream& StdDbgStream() noexcept { return *(Singleton()->Out); } int StdDbgLevel() noexcept { return Singleton()->Level; }