45 lines
903 B
Go
45 lines
903 B
Go
package log
|
|
|
|
import (
|
|
"fmt"
|
|
"go.uber.org/zap"
|
|
"go.uber.org/zap/zapcore"
|
|
"testing"
|
|
)
|
|
|
|
func testLogger(t *testing.T, level zapcore.Level) {
|
|
_ = t
|
|
Open("test.log", level)
|
|
defer Close()
|
|
|
|
Debug("debug. ", zap.String("name", "liu"))
|
|
Info("info. ", zap.Error(fmt.Errorf("this is an error")))
|
|
Warn("warn.", zap.Int64("int64", 111))
|
|
Error("error.", zap.Bool("bool", true))
|
|
Fatal("fatal. ", zap.String("name", "liu"))
|
|
DebugF("debugF: %.2f", 1.23)
|
|
InfoF("infoF: %.2f", 1.23)
|
|
WarnF("warnF: %.2f", 1.23)
|
|
ErrorF("errorF: %.2f", 1.23)
|
|
FatalF("fatalF: %.2f", 1.23)
|
|
}
|
|
|
|
func TestLogger(t *testing.T) {
|
|
testLogger(t, DebugL)
|
|
testLogger(t, InfoL)
|
|
testLogger(t, WarnL)
|
|
testLogger(t, ErrorL)
|
|
}
|
|
|
|
func testStackTrace(t *testing.T, level zapcore.Level) {
|
|
_ = t
|
|
Open("test.log", level)
|
|
defer Close()
|
|
stack := StackTrace()
|
|
Debug(stack)
|
|
}
|
|
|
|
func TestStackTrace(t *testing.T) {
|
|
testStackTrace(t, DebugL)
|
|
}
|