From 2bf49ddf90d4a43a3f325b339f69326d75ca7cc7 Mon Sep 17 00:00:00 2001 From: Smitty Date: Wed, 13 Jan 2021 15:53:59 -0500 Subject: [PATCH] Provide example when format string is rate limited Here's an example log line in the new format: [RATE LIMITED] format string "open-conn-track: timeout opening %v; no associated peer node" (example: "open-conn-track: timeout opening ([ip] => [ip]); no associated peer node") This should make debugging logging issues a bit easier, and give more context as to why something was rate limited. This change was proposed in a comment on #1110. Signed-off-by: Smitty --- types/logger/logger.go | 2 +- types/logger/logger_test.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/types/logger/logger.go b/types/logger/logger.go index e9a2229fe..646becdcd 100644 --- a/types/logger/logger.go +++ b/types/logger/logger.go @@ -132,7 +132,7 @@ func RateLimitedFn(logf Logf, f time.Duration, burst int, maxCache int) Logf { logf(format, args...) case warn: // For the warning, log the specific format string - logf("[RATE LIMITED] format string \"%s\"", format) + logf("[RATE LIMITED] format string \"%s\" (example: \"%s\")", format, fmt.Sprintf(format, args...)) } } } diff --git a/types/logger/logger_test.go b/types/logger/logger_test.go index ce9fa942c..15827e916 100644 --- a/types/logger/logger_test.go +++ b/types/logger/logger_test.go @@ -45,8 +45,8 @@ func TestRateLimiter(t *testing.T) { "templated format string no. 0", "boring string with constant formatting (constant)", "templated format string no. 1", - "[RATE LIMITED] format string \"boring string with constant formatting %s\"", - "[RATE LIMITED] format string \"templated format string no. %d\"", + "[RATE LIMITED] format string \"boring string with constant formatting %s\" (example: \"boring string with constant formatting (constant)\")", + "[RATE LIMITED] format string \"templated format string no. %d\" (example: \"templated format string no. 2\")", "Make sure this string makes it through the rest (that are blocked) 4", "4 shouldn't get filtered.", }