From 2e19e297d9dcfacd2a032157bf4eed52fb6a0467 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Mon, 30 Jul 2018 22:12:20 -0500 Subject: [PATCH] [ox/trace] Add environment variable to enable logging --- deps/ox/src/ox/trace/trace.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/deps/ox/src/ox/trace/trace.cpp b/deps/ox/src/ox/trace/trace.cpp index 0fe09a95..a590a446 100644 --- a/deps/ox/src/ox/trace/trace.cpp +++ b/deps/ox/src/ox/trace/trace.cpp @@ -17,6 +17,8 @@ namespace ox::trace { +static const auto OxPrintTrace = std::getenv("OXTRACE") != nullptr; + OutStream::OutStream(const char *file, int line, const char *ch, const char *msg) { m_msg.file = file; m_msg.line = line; @@ -41,9 +43,11 @@ StdOutStream::StdOutStream(const char *file, int line, const char *ch, const cha StdOutStream::~StdOutStream() { #if defined(OX_USE_STDLIB) - std::cout << std::setw(53) << std::left << m_msg.ch.c_str() << '|'; - std::cout << std::setw(65) << std::left << m_msg.msg.c_str() << '|'; - std::cout << " " << m_msg.file.c_str() << ':' << m_msg.line << "\n"; + if (OxPrintTrace) { + std::cout << std::setw(53) << std::left << m_msg.ch.c_str() << '|'; + std::cout << std::setw(65) << std::left << m_msg.msg.c_str() << '|'; + std::cout << " " << m_msg.file.c_str() << ':' << m_msg.line << "\n"; + } #endif }