add log test

This commit is contained in:
ehlxr 2019-11-06 10:12:49 +08:00
parent 9712dbfd2c
commit 98605355bb
2 changed files with 3 additions and 4 deletions

3
go.mod
View File

@ -3,9 +3,6 @@ module github.com/ehlxr/log
go 1.13 go 1.13
require ( require (
github.com/ehlxr/logger v0.0.0-20191105075740-0235eee42e0f
github.com/lestrrat-go/file-rotatelogs v2.2.0+incompatible
github.com/lestrrat-go/strftime v0.0.0-20190725011945-5c849dd2c51d // indirect
github.com/pkg/errors v0.8.1 github.com/pkg/errors v0.8.1
go.uber.org/zap v1.12.0 go.uber.org/zap v1.12.0
gopkg.in/natefinch/lumberjack.v2 v2.0.0 gopkg.in/natefinch/lumberjack.v2 v2.0.0

4
log.go
View File

@ -220,6 +220,7 @@ func trimCallerFilePath(ec zapcore.EntryCaller) string {
} }
func fileWriteSyncer(name string) zapcore.WriteSyncer { func fileWriteSyncer(name string) zapcore.WriteSyncer {
// go get github.com/lestrrat-go/file-rotatelogs
// writer, err := rotatelogs.New( // writer, err := rotatelogs.New(
// name+".%Y%m%d", // name+".%Y%m%d",
// rotatelogs.WithLinkName(name), // 生成软链,指向最新日志文件 // rotatelogs.WithLinkName(name), // 生成软链,指向最新日志文件
@ -245,7 +246,8 @@ func fileWriteSyncer(name string) zapcore.WriteSyncer {
func writeCrashLog(file string) { func writeCrashLog(file string) {
err := os.MkdirAll(path.Dir(file), os.ModePerm) err := os.MkdirAll(path.Dir(file), os.ModePerm)
if err != nil { if err != nil {
log.Fatalf("make crash log dir error. %v", errors.WithStack(err)) log.Fatalf("make crash log dir error. %v",
errors.WithStack(err))
} }
crash.NewCrashLog(file) crash.NewCrashLog(file)