perf(protocol): skip string debug escaping when proto debug is off

output_escape() was called on every send_str/receive_str even when
LOG_DEBUG_PROTO logging was disabled, allocating and scanning the whole
payload for a line that log_debug_message() then discarded.  Add a
log_debug_enabled(flag) gate mirroring log_debug_message()'s own filter and
check it before escaping.  Redacted (secret) strings still log the same
<redacted> marker; no observable log output changes.
This commit is contained in:
2026-09-12 16:54:43 +02:00
parent 1ba6372017
commit 87585e9881
4 changed files with 30 additions and 2 deletions
+2 -2
View File
@@ -432,7 +432,7 @@ static bool protocol_send_str_impl(ProtocolSession* session, const char* data, b
return false;
if (redact) {
log_debug_message(LOG_DEBUG_PROTO, "Send String: <redacted>");
} else {
} else if (log_debug_enabled(LOG_DEBUG_PROTO)) {
char* escaped_data = output_escape(data, log_get_8_bit_output());
log_debug_message(LOG_DEBUG_PROTO, "Send String: %s",
escaped_data ? escaped_data : "<allocation failed>");
@@ -465,7 +465,7 @@ static char* protocol_receive_str_impl(ProtocolSession* session, bool redact) {
data[size] = '\0';
if (redact) {
log_debug_message(LOG_DEBUG_PROTO, "Received String: <redacted>");
} else {
} else if (log_debug_enabled(LOG_DEBUG_PROTO)) {
char* escaped_data = output_escape(data, log_get_8_bit_output());
log_debug_message(LOG_DEBUG_PROTO, "Received String: %s",
escaped_data ? escaped_data : "<allocation failed>");