Fix log format bug

This commit is contained in:
Ming Deng
2021-02-05 22:26:52 +08:00
parent f9ee9099a8
commit cec95bb6d0
7 changed files with 16 additions and 4 deletions

View File

@@ -37,7 +37,7 @@ func (lm *LogMsg) OldStyleFormat() string {
msg := lm.Msg
if len(lm.Args) > 0 {
lm.Msg = fmt.Sprintf(lm.Msg, lm.Args...)
msg = fmt.Sprintf(lm.Msg, lm.Args...)
}
msg = lm.Prefix + " " + msg

View File

@@ -41,4 +41,8 @@ func TestLogMsg_OldStyleFormat(t *testing.T) {
res = lg.OldStyleFormat()
assert.Equal(t, "[D] [/user/home/main.go:13] Cus Hello, world", res)
lg.Msg = "hello, %s"
lg.Args = []interface{}{"world"}
assert.Equal(t, "[D] [/user/home/main.go:13] Cus hello, world", lg.OldStyleFormat())
}

View File

@@ -18,9 +18,10 @@ import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestBeeLogger_DelLogger(t *testing.T) {
func TestBeeLoggerDelLogger(t *testing.T) {
prefix := "My-Cus"
l := GetLogger(prefix)
assert.NotNil(t, l)