go-utils/utils/log/log_test.go

48 lines
973 B
Go
Raw Normal View History

2017-06-26 07:35:38 +00:00
package log
import (
"fmt"
"github.com/sirupsen/logrus"
2020-07-20 02:06:17 +00:00
"testing"
2017-06-26 07:35:38 +00:00
)
func TestSetting(t *testing.T) {
SetFn(true)
SetLogLevel(logrus.DebugLevel)
SetLogFormatter(&logrus.JSONFormatter{TimestampFormat: "2006-01-02 15:04:05"})
// SetLogFormatter(&prefixed.TextFormatter{
// ForceFormatting: true,
// QuoteEmptyFields: true,
// TimestampFormat: "2006-01-02 15:04:05",
// FullTimestamp: true,
// ForceColors: true,
// })
}
func TestInfo(t *testing.T) {
Info("this is a Info log test.")
InfoWithFields(Fields{
"id": 10001,
"name": "hello",
}, "this is a InfoWithFields log test.")
Infof("this is a %s log test.", "Infof")
InfofWithFields(Fields{
"id": 10001,
"name": "hello",
}, "this is a %s log test.", "InfofWithFields")
}
func TestPanic(t *testing.T) {
defer func() {
if x := recover(); x != nil {
fmt.Println("recover:", x)
}
}()
Panic("this is a Panic log test.")
Panicf("this is a %s log test.", "Panicf")
}