fix: log 包日志配置无效问题修复
This commit is contained in:
parent
7f3fc89c9d
commit
c6b929afe8
|
@ -4,7 +4,6 @@ import (
|
|||
"go.uber.org/zap"
|
||||
"go.uber.org/zap/zapcore"
|
||||
"gopkg.in/natefinch/lumberjack.v2"
|
||||
"os"
|
||||
)
|
||||
|
||||
type Encoder struct {
|
||||
|
@ -29,23 +28,10 @@ func (slf *Encoder) Build(options ...LoggerOption) *Minotaur {
|
|||
panic(err)
|
||||
}
|
||||
options = append([]LoggerOption{zap.AddCaller(), zap.AddCallerSkip(1)}, options...)
|
||||
l = l.WithOptions(options...)
|
||||
if len(slf.cores) == 0 {
|
||||
// stdout、stderr,不使用 lumberjack.Logger
|
||||
slf.cores = append(slf.cores, zapcore.NewCore(
|
||||
slf.e,
|
||||
zapcore.Lock(os.Stdout),
|
||||
zapcore.InfoLevel,
|
||||
))
|
||||
slf.cores = append(slf.cores, zapcore.NewCore(
|
||||
slf.e,
|
||||
zapcore.Lock(os.Stderr),
|
||||
zapcore.ErrorLevel,
|
||||
))
|
||||
}
|
||||
l = l.WithOptions(zap.WrapCore(func(core zapcore.Core) zapcore.Core {
|
||||
return zapcore.NewTee(slf.cores...)
|
||||
options = append(options, zap.WrapCore(func(core zapcore.Core) zapcore.Core {
|
||||
return zapcore.NewTee(append(slf.cores, core)...)
|
||||
}))
|
||||
l = l.WithOptions(options...)
|
||||
return &Minotaur{
|
||||
Logger: l,
|
||||
Sugared: l.Sugar(),
|
||||
|
|
|
@ -46,6 +46,8 @@ func Default(opts ...Option) *Encoder {
|
|||
EncodeDuration: zapcore.StringDurationEncoder,
|
||||
EncodeCaller: zapcore.ShortCallerEncoder,
|
||||
},
|
||||
OutputPaths: []string{"stderr"},
|
||||
ErrorOutputPaths: []string{"stderr"},
|
||||
}
|
||||
|
||||
// 应用选项
|
||||
|
|
|
@ -6,6 +6,11 @@ import (
|
|||
)
|
||||
|
||||
var launchTime = time.Now()
|
||||
var pid int
|
||||
|
||||
func init() {
|
||||
pid = os.Getpid()
|
||||
}
|
||||
|
||||
// LaunchTime 获取程序启动时间
|
||||
func LaunchTime() time.Time {
|
||||
|
@ -16,3 +21,8 @@ func LaunchTime() time.Time {
|
|||
func Hostname() string {
|
||||
return os.Getenv("HOSTNAME")
|
||||
}
|
||||
|
||||
// PID 获取进程 PID
|
||||
func PID() int {
|
||||
return pid
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue