Skip to content

Commit

Permalink
Make some log only available in debug builds
Browse files Browse the repository at this point in the history
  • Loading branch information
Yaraslaut committed Jul 24, 2024
1 parent 07a3379 commit 39430ab
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 12 deletions.
3 changes: 3 additions & 0 deletions src/crispy/logstore.h
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down
10 changes: 2 additions & 8 deletions src/vtbackend/Line.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ struct TrivialLineInflater

InflatedLineBuffer<Cell> 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<unsigned>::max());
assert(result.stop_condition == unicode::StopCondition::EndOfInput);
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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);
Expand All @@ -220,20 +218,16 @@ struct TrivialLineInflater
unicode::ConvertResult const r = unicode::from_utf8(utf8DecoderState, static_cast<uint8_t>(ch));
if (auto const* cp = std::get_if<unicode::Success>(&r))
{
std::cout << fmt::format(" - codepoint: U+{:X}\n", (unsigned) cp->value);
if (cell.codepointCount() == 0)
cell.setCharacter(cp->value);
else
(void) cell.appendCharacter(cp->value);
}
}

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);
}
Expand Down
14 changes: 12 additions & 2 deletions src/vtbackend/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
1 change: 0 additions & 1 deletion src/vtparser/Parser-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,6 @@ auto Parser<EventListener, TraceStateChanges>::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() };
Expand Down
7 changes: 6 additions & 1 deletion src/vtparser/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 39430ab

Please sign in to comment.