From c76b423476ed2e1e8f23339484363442407cf537 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20G=C3=B6m=C3=B6ri?= Date: Wed, 9 Oct 2024 01:07:52 +0200 Subject: [PATCH] Optimize (not) printing empty string from formatter Sometimes it is handy to implement some additional filtering in a custom formatter function. In this case the formatter can return the empty string if it wants to ignore a trace message. Optimize the formatting so in the empty string case it does not send an io request to the IO server. This avoids a "flickering prompt" effect (when the empty string is printed) in case of 1000s of ignored trace messages per second. --- src/recon_trace.erl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/recon_trace.erl b/src/recon_trace.erl index 975f536..62b3b67 100644 --- a/src/recon_trace.erl +++ b/src/recon_trace.erl @@ -393,7 +393,10 @@ formatter(Tracer, IOServer, FormatterFun) -> {'EXIT', Tracer, Reason} -> exit(Reason); TraceMsg -> - io:format(IOServer, FormatterFun(TraceMsg), []), + case FormatterFun(TraceMsg) of + "" -> ok; + Formatted -> io:format(IOServer, Formatted, []) + end, formatter(Tracer, IOServer, FormatterFun) end.