update at 2021-01-01 23:12:00 by ehlxr

master v0.0.9
ehlxr 2021-01-01 23:12:00 +08:00
parent c03451395f
commit 7eee167d91
4 changed files with 13 additions and 8 deletions

11
log.go
View File

@ -35,6 +35,7 @@ type logConfig struct {
CrashLogFilename string
ErrorLogFilename string
EnableLineNumber bool
AddCallerSkip int
// enable the truncation of the level text to 4 characters.
EnableLevelTruncation bool
@ -62,6 +63,10 @@ func (config *logConfig) Init() {
logger = config.newLogger().Sugar()
}
func (config *logConfig) New() *zap.SugaredLogger {
return config.newLogger().Sugar()
}
func NewLogConfig() *logConfig {
return &logConfig{
Level: DebugLevel,
@ -113,7 +118,7 @@ func (config *logConfig) newLogger() *zap.Logger {
var options []zap.Option
if config.EnableLineNumber {
options = append(options, zap.AddCaller(), zap.AddCallerSkip(1))
options = append(options, zap.AddCaller(), zap.AddCallerSkip(config.AddCallerSkip))
}
if config.EnableErrorStacktrace {
@ -265,3 +270,7 @@ func writeCrashLog(file string) {
func Fields(args ...interface{}) {
logger = logger.With(args...)
}
func With(l *zap.SugaredLogger, args ...interface{}) *zap.SugaredLogger {
return l.With(args...)
}

View File

@ -21,10 +21,10 @@ func TestLogWithConfig(t *testing.T) {
config.Init()
With("traceid", float64(21221212122))
Fields("traceid", float64(21221212122))
Debugf("this is %s message", "debug")
config.Init()
With(zap.String("traceid", "12123123123"))
Fields(zap.String("traceid", "12123123123"))
Infof("this is %s message", "info")
// Errorf("this is %s message", "error")
// Panicf("this is %s message", "panic")

View File

@ -1,9 +1,5 @@
package log
func With(args ...interface{}) {
logger = logger.With(args...)
}
func Debug(args ...interface{}) {
logger.Debug(args...)
}

View File

@ -1 +1 @@
v0.0.8
v0.0.9