go-utils/utils/log/log_test.go

49 lines
974 B
Go
Raw Normal View History

2017-06-26 07:35:38 +00:00
package log
import (
"fmt"
"testing"
"github.com/sirupsen/logrus"
)
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")
}