1
0
mirror of https://github.com/astaxie/beego.git synced 2024-06-02 08:03:28 +00:00
Beego/pkg/infrastructure/logs/formatter_test.go
2020-09-19 20:18:09 +08:00

29 lines
589 B
Go

package logs
import (
"strconv"
"testing"
"time"
)
func TestPatternLogFormatter(t *testing.T) {
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)
}
}