-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9f27da2
commit d3ad49d
Showing
16 changed files
with
347 additions
and
400 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package logger | ||
|
||
import "github.com/kercylan98/minotaur/utils/log" | ||
|
||
type Ants struct { | ||
} | ||
|
||
func (slf *Ants) Printf(format string, args ...interface{}) { | ||
log.Warn(format, log.Any("args", args)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package logger | ||
|
||
import ( | ||
"fmt" | ||
"github.com/kercylan98/minotaur/utils/log" | ||
) | ||
|
||
type GNet struct { | ||
} | ||
|
||
func (slf *GNet) Debugf(format string, args ...interface{}) { | ||
log.Debug(fmt.Sprintf(format, args...)) | ||
} | ||
|
||
func (slf *GNet) Infof(format string, args ...interface{}) { | ||
log.Info(fmt.Sprintf(format, args...)) | ||
} | ||
|
||
func (slf *GNet) Warnf(format string, args ...interface{}) { | ||
log.Warn(fmt.Sprintf(format, args...)) | ||
} | ||
|
||
func (slf *GNet) Errorf(format string, args ...interface{}) { | ||
log.Error(fmt.Sprintf(format, args...)) | ||
} | ||
|
||
func (slf *GNet) Fatalf(format string, args ...interface{}) { | ||
log.Fatal(fmt.Sprintf(format, args...)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,53 @@ | ||
package log | ||
|
||
import ( | ||
"go.uber.org/zap" | ||
"go.uber.org/zap/zapcore" | ||
"time" | ||
"gopkg.in/natefinch/lumberjack.v2" | ||
"os" | ||
) | ||
|
||
type Encoder = zapcore.Encoder | ||
type Encoder struct { | ||
e zapcore.Encoder | ||
cores []Core | ||
conf *Config | ||
} | ||
|
||
func (slf *Encoder) Split(config *lumberjack.Logger) *Encoder { | ||
slf.cores = append(slf.cores, zapcore.NewCore(slf.e, zapcore.AddSync(config), zapcore.DebugLevel)) | ||
return slf | ||
} | ||
|
||
func (slf *Encoder) AddCore(ws WriteSyncer, enab LevelEnabler) *Encoder { | ||
slf.cores = append(slf.cores, zapcore.NewCore(slf.e, ws, enab)) | ||
return slf | ||
} | ||
|
||
// NewEncoder 创建一个 Minotaur 默认使用的编码器 | ||
func NewEncoder() Encoder { | ||
return zapcore.NewConsoleEncoder(zapcore.EncoderConfig{ | ||
MessageKey: "msg", | ||
LevelKey: "level", | ||
EncodeLevel: zapcore.CapitalLevelEncoder, | ||
TimeKey: "ts", | ||
EncodeTime: func(t time.Time, enc zapcore.PrimitiveArrayEncoder) { | ||
enc.AppendString(t.Format(time.DateTime)) | ||
}, | ||
CallerKey: "file", | ||
EncodeCaller: zapcore.ShortCallerEncoder, | ||
EncodeDuration: func(d time.Duration, enc zapcore.PrimitiveArrayEncoder) { | ||
enc.AppendInt64(int64(d) / 1000000) | ||
}, | ||
}) | ||
func (slf *Encoder) Build(options ...LoggerOption) *Minotaur { | ||
l, err := slf.conf.Build() | ||
if err != nil { | ||
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...) | ||
})) | ||
return &Minotaur{ | ||
Logger: l, | ||
Sugared: l.Sugar(), | ||
} | ||
} |
Oops, something went wrong.