From 39430abb1fc19a1f078eedefb508baa1dfa63dac Mon Sep 17 00:00:00 2001 From: Yaraslau Tamashevich Date: Wed, 24 Jul 2024 22:42:51 +0300 Subject: [PATCH] Make some log only available in debug builds --- src/crispy/logstore.h | 3 +++ src/vtbackend/Line.cpp | 10 ++-------- src/vtbackend/logging.h | 14 ++++++++++++-- src/vtparser/Parser-impl.h | 1 - src/vtparser/Parser.h | 7 ++++++- 5 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/crispy/logstore.h b/src/crispy/logstore.h index c6dbbd0b5e..ce6b0969dc 100644 --- a/src/crispy/logstore.h +++ b/src/crispy/logstore.h @@ -350,6 +350,9 @@ inline void sink::set_writer(writer writer) // }}} auto inline errorLog = logstore::category("error", "Error Logger", category::state::Enabled); +// clang-format off +auto inline emptyLog = []() { return [](auto&&...) {};}; +// clang-format on #define errorLog() (::logstore::errorLog()) diff --git a/src/vtbackend/Line.cpp b/src/vtbackend/Line.cpp index 969e5797f8..da8774e0d8 100644 --- a/src/vtbackend/Line.cpp +++ b/src/vtbackend/Line.cpp @@ -168,7 +168,8 @@ struct TrivialLineInflater InflatedLineBuffer inflate() && { - vtParserLog()("Inflating TrivialLineBuffer: '{}'", input.text.data() ? crispy::escape(input.text.data()) : ""); + vtParserLog()("Inflating TrivialLineBuffer: '{}'", + input.text.data() ? crispy::escape(input.text.data()) : ""); auto lineSegmenter = unicode::grapheme_line_segmenter { *this, input.text.view() }; [[maybe_unused]] auto result = lineSegmenter.process(std::numeric_limits::max()); assert(result.stop_condition == unicode::StopCondition::EndOfInput); @@ -188,7 +189,6 @@ struct TrivialLineInflater void on_invalid(std::string_view /*invalid*/) noexcept { - fmt::print("inflate invalid\n"); static constexpr char32_t ReplacementCharacter { 0xFFFD }; columns.emplace_back(); @@ -198,7 +198,6 @@ struct TrivialLineInflater void on_ascii(std::string_view text) noexcept { - fmt::print("inflate ASCII: '{}'\n", text); for (auto const ch: text) { columns.emplace_back(); @@ -209,7 +208,6 @@ struct TrivialLineInflater void on_grapheme_cluster(std::string_view text, unsigned width) noexcept { - fmt::print("inflate GC: '{}', width: {}\n", text, width); columns.emplace_back(input.textAttributes, input.hyperlink); Cell& cell = columns.back(); cell.setHyperlink(input.hyperlink); @@ -220,7 +218,6 @@ struct TrivialLineInflater unicode::ConvertResult const r = unicode::from_utf8(utf8DecoderState, static_cast(ch)); if (auto const* cp = std::get_if(&r)) { - std::cout << fmt::format(" - codepoint: U+{:X}\n", (unsigned) cp->value); if (cell.codepointCount() == 0) cell.setCharacter(cp->value); else @@ -228,12 +225,9 @@ struct TrivialLineInflater } } - fmt::print(" -> result (UTF-8): \"{}\"\n", cell.toUtf8()); - // Fill remaining columns for wide characters for (unsigned i = 1; i < width; ++i) { - std::cout << fmt::format(" - continuation\n"); columns.emplace_back(input.textAttributes.with(CellFlag::WideCharContinuation), input.hyperlink); cell.setWidth(width); } diff --git a/src/vtbackend/logging.h b/src/vtbackend/logging.h index e78e937940..774c7d2888 100644 --- a/src/vtbackend/logging.h +++ b/src/vtbackend/logging.h @@ -8,10 +8,20 @@ namespace vtbackend auto const inline terminalLog = logstore::category("vt.session", "Logs general terminal events."); auto const inline inputLog = logstore::category("vt.input", "Logs terminal keyboard/mouse input events."); -auto const inline vtParserLog = logstore::category("vt.parser", "Logs terminal parser errors."); +auto const inline vtParserLog = +#if defined(DEBUG) + logstore::category("vt.parser", "Logs terminal parser errors."); +#else + logstore::emptyLog; +#endif #if defined(LIBTERMINAL_LOG_TRACE) -auto const inline vtTraceSequenceLog = logstore::category("vt.trace.sequence", "Logs terminal screen trace."); +auto const inline vtTraceSequenceLog = + #if defined(DEBUG) + logstore::category("vt.trace.sequence", "Logs terminal screen trace."); + #else + logstore::emptyLog; + #endif #endif auto const inline renderBufferLog = logstore::category("vt.renderbuffer", "Render Buffer Objects"); diff --git a/src/vtparser/Parser-impl.h b/src/vtparser/Parser-impl.h index ccc0a6b8d7..1c864fbecf 100644 --- a/src/vtparser/Parser-impl.h +++ b/src/vtparser/Parser-impl.h @@ -498,7 +498,6 @@ auto Parser::makeParseBulkResult(char const* i { unicode::grapheme_segmentation_result const flushResult = _graphemeLineSegmenter.flush(maxCharCount - resultWidth); - std::cout << "flushResult: " << flushResult << '\n'; if (!flushResult.text.empty()) { auto const text = std::string_view { flushResult.text.data(), flushResult.text.size() }; diff --git a/src/vtparser/Parser.h b/src/vtparser/Parser.h index b631d06671..ba7b1cfd77 100644 --- a/src/vtparser/Parser.h +++ b/src/vtparser/Parser.h @@ -30,7 +30,12 @@ namespace vtparser #define VTPARSER_NOINLINE /*!*/ #endif -auto const inline vtTraceParserLog = logstore::category("vt.trace.parser", "Logs terminal parser trace."); +auto const inline vtTraceParserLog = +#if defined(DEBUG) + logstore::category("vt.trace.parser", "Logs terminal parser trace."); +#else + logstore::emptyLog; +#endif // NOLINTBEGIN(readability-identifier-naming) enum class State : uint8_t