fix support for format

This commit is contained in:
kingecg 2024-10-01 15:55:21 +08:00
parent d13d851819
commit 45c66585ad
2 changed files with 11 additions and 1 deletions

View File

@ -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
}

View File

@ -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{