From 1ef26e0c092988a9d5729623b589a66e24d2d567 Mon Sep 17 00:00:00 2001 From: Ben Wiederhake Date: Fri, 28 Aug 2020 09:56:51 +0200 Subject: [PATCH] AK: Provide off-switch for dbg() output --- AK/LogStream.cpp | 14 +++++++++++++- AK/LogStream.h | 7 +++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/AK/LogStream.cpp b/AK/LogStream.cpp index 9037f45fb3a..2fead23a5e6 100644 --- a/AK/LogStream.cpp +++ b/AK/LogStream.cpp @@ -163,13 +163,25 @@ KernelLogStream::~KernelLogStream() DebugLogStream::~DebugLogStream() { - if (!empty()) { + if (!empty() && s_enabled) { char newline = '\n'; write(&newline, 1); dbgputstr(reinterpret_cast(data()), size()); } } +void DebugLogStream::set_enabled(bool enabled) +{ + s_enabled = enabled; +} + +bool DebugLogStream::is_enabled() +{ + return s_enabled; +} + +bool DebugLogStream::s_enabled = true; + #ifndef KERNEL StdLogStream::~StdLogStream() { diff --git a/AK/LogStream.h b/AK/LogStream.h index 1a1a937ad0e..59c81ca1da3 100644 --- a/AK/LogStream.h +++ b/AK/LogStream.h @@ -115,6 +115,13 @@ class DebugLogStream final : public BufferedLogStream { public: DebugLogStream() { } virtual ~DebugLogStream() override; + + // DebugLogStream only checks `enabled` and possibly generates output while the destructor runs. + static void set_enabled(bool); + static bool is_enabled(); + +private: + static bool s_enabled; }; #if !defined(KERNEL)