Skip to content

Commit 39430ab

Browse files
committed
Make some log only available in debug builds
1 parent 07a3379 commit 39430ab

File tree

5 files changed

+23
-12
lines changed

5 files changed

+23
-12
lines changed

src/crispy/logstore.h

+3
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,9 @@ inline void sink::set_writer(writer writer)
350350
// }}}
351351

352352
auto inline errorLog = logstore::category("error", "Error Logger", category::state::Enabled);
353+
// clang-format off
354+
auto inline emptyLog = []() { return [](auto&&...) {};};
355+
// clang-format on
353356

354357
#define errorLog() (::logstore::errorLog())
355358

src/vtbackend/Line.cpp

+2-8
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,8 @@ struct TrivialLineInflater
168168

169169
InflatedLineBuffer<Cell> inflate() &&
170170
{
171-
vtParserLog()("Inflating TrivialLineBuffer: '{}'", input.text.data() ? crispy::escape(input.text.data()) : "");
171+
vtParserLog()("Inflating TrivialLineBuffer: '{}'",
172+
input.text.data() ? crispy::escape(input.text.data()) : "");
172173
auto lineSegmenter = unicode::grapheme_line_segmenter { *this, input.text.view() };
173174
[[maybe_unused]] auto result = lineSegmenter.process(std::numeric_limits<unsigned>::max());
174175
assert(result.stop_condition == unicode::StopCondition::EndOfInput);
@@ -188,7 +189,6 @@ struct TrivialLineInflater
188189

189190
void on_invalid(std::string_view /*invalid*/) noexcept
190191
{
191-
fmt::print("inflate invalid\n");
192192
static constexpr char32_t ReplacementCharacter { 0xFFFD };
193193

194194
columns.emplace_back();
@@ -198,7 +198,6 @@ struct TrivialLineInflater
198198

199199
void on_ascii(std::string_view text) noexcept
200200
{
201-
fmt::print("inflate ASCII: '{}'\n", text);
202201
for (auto const ch: text)
203202
{
204203
columns.emplace_back();
@@ -209,7 +208,6 @@ struct TrivialLineInflater
209208

210209
void on_grapheme_cluster(std::string_view text, unsigned width) noexcept
211210
{
212-
fmt::print("inflate GC: '{}', width: {}\n", text, width);
213211
columns.emplace_back(input.textAttributes, input.hyperlink);
214212
Cell& cell = columns.back();
215213
cell.setHyperlink(input.hyperlink);
@@ -220,20 +218,16 @@ struct TrivialLineInflater
220218
unicode::ConvertResult const r = unicode::from_utf8(utf8DecoderState, static_cast<uint8_t>(ch));
221219
if (auto const* cp = std::get_if<unicode::Success>(&r))
222220
{
223-
std::cout << fmt::format(" - codepoint: U+{:X}\n", (unsigned) cp->value);
224221
if (cell.codepointCount() == 0)
225222
cell.setCharacter(cp->value);
226223
else
227224
(void) cell.appendCharacter(cp->value);
228225
}
229226
}
230227

231-
fmt::print(" -> result (UTF-8): \"{}\"\n", cell.toUtf8());
232-
233228
// Fill remaining columns for wide characters
234229
for (unsigned i = 1; i < width; ++i)
235230
{
236-
std::cout << fmt::format(" - continuation\n");
237231
columns.emplace_back(input.textAttributes.with(CellFlag::WideCharContinuation), input.hyperlink);
238232
cell.setWidth(width);
239233
}

src/vtbackend/logging.h

+12-2
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,20 @@ namespace vtbackend
88

99
auto const inline terminalLog = logstore::category("vt.session", "Logs general terminal events.");
1010
auto const inline inputLog = logstore::category("vt.input", "Logs terminal keyboard/mouse input events.");
11-
auto const inline vtParserLog = logstore::category("vt.parser", "Logs terminal parser errors.");
11+
auto const inline vtParserLog =
12+
#if defined(DEBUG)
13+
logstore::category("vt.parser", "Logs terminal parser errors.");
14+
#else
15+
logstore::emptyLog;
16+
#endif
1217

1318
#if defined(LIBTERMINAL_LOG_TRACE)
14-
auto const inline vtTraceSequenceLog = logstore::category("vt.trace.sequence", "Logs terminal screen trace.");
19+
auto const inline vtTraceSequenceLog =
20+
#if defined(DEBUG)
21+
logstore::category("vt.trace.sequence", "Logs terminal screen trace.");
22+
#else
23+
logstore::emptyLog;
24+
#endif
1525
#endif
1626

1727
auto const inline renderBufferLog = logstore::category("vt.renderbuffer", "Render Buffer Objects");

src/vtparser/Parser-impl.h

-1
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,6 @@ auto Parser<EventListener, TraceStateChanges>::makeParseBulkResult(char const* i
498498
{
499499
unicode::grapheme_segmentation_result const flushResult =
500500
_graphemeLineSegmenter.flush(maxCharCount - resultWidth);
501-
std::cout << "flushResult: " << flushResult << '\n';
502501
if (!flushResult.text.empty())
503502
{
504503
auto const text = std::string_view { flushResult.text.data(), flushResult.text.size() };

src/vtparser/Parser.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,12 @@ namespace vtparser
3030
#define VTPARSER_NOINLINE /*!*/
3131
#endif
3232

33-
auto const inline vtTraceParserLog = logstore::category("vt.trace.parser", "Logs terminal parser trace.");
33+
auto const inline vtTraceParserLog =
34+
#if defined(DEBUG)
35+
logstore::category("vt.trace.parser", "Logs terminal parser trace.");
36+
#else
37+
logstore::emptyLog;
38+
#endif
3439

3540
// NOLINTBEGIN(readability-identifier-naming)
3641
enum class State : uint8_t

0 commit comments

Comments
 (0)