1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-05 13:50:58 +00:00
Beego/pkg/infrastructure/logs/formatter_test.go

29 lines
589 B
Go
Raw Normal View History

package logs
import (
"strconv"
"testing"
"time"
)
func TestPatternLogFormatter(t *testing.T) {
2020-09-19 12:18:09 +00:00
tes := &PatternLogFormatter{
Pattern: "%F:%n|%w%t>> %m",
WhenFormat: "2006-01-02",
}
when := time.Now()
lm := &LogMsg{
Msg: "message",
FilePath: "/User/go/beego/main.go",
Level: LevelWarn,
LineNumber: 10,
When: when,
}
got := tes.ToString(lm)
want := lm.FilePath + ":" + strconv.Itoa(lm.LineNumber) + "|" +
when.Format(tes.WhenFormat) + levelPrefix[lm.Level-1] + ">> " + lm.Msg
if got != want {
t.Errorf("want %s, got %s", want, got)
}
}