support logger auto call

This commit is contained in:
yanghao05
2023-01-29 15:27:50 +08:00
parent 34b3978c5a
commit 7151c52543
13 changed files with 284 additions and 589 deletions

View File

@@ -0,0 +1,23 @@
package logger
import (
"strings"
"go.uber.org/zap/zapcore"
)
type LevelWriter struct {
Logger *Logger
Level zapcore.Level
}
func (w LevelWriter) Write(p []byte) (n int, err error) {
str := strings.TrimSpace(string(p))
switch w.Level {
case zapcore.InfoLevel:
Info(str)
case zapcore.ErrorLevel:
Error(str)
}
return len(p), nil
}