From 45c66585adaf9683ff31f1e6aa8579cff45aa85d Mon Sep 17 00:00:00 2001 From: kingecg Date: Tue, 1 Oct 2024 15:55:21 +0800 Subject: [PATCH] fix support for format --- format.go | 2 +- format_test.go | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/format.go b/format.go index b3960a3..ef4ba2a 100644 --- a/format.go +++ b/format.go @@ -36,7 +36,7 @@ func isFormatString(f interface{}) bool { return false } // 尝试使用空接口来格式化字符串 - m := fmt.Sprintf(s, []interface{}{}) + m := fmt.Sprintf(s, []interface{}{}...) return strings.Index(m, "MISSING") != -1 } diff --git a/format_test.go b/format_test.go index 70b40b4..3cde162 100644 --- a/format_test.go +++ b/format_test.go @@ -22,6 +22,16 @@ func TestFormat(t *testing.T) { }, want: "test_category : INFO - key: value", }, + { + name: "Info level with one format string", + logEvent: LogEvent{ + Ts: time.Now(), + Category: "test_category", + Level: Info, + Data: []interface{}{"%s", "key"}, + }, + want: "test_category : INFO - key", + }, { name: "Error level without format string", logEvent: LogEvent{