impl.go 1.26 KB
Newer Older
kzkzzzz's avatar
kzkzzzz committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
package logz

import "go-micro.dev/v4/logger"

// 实现go-micro的logger
var _ logger.Logger = &zapStd{}

func (z *zapStd) Init(options ...logger.Option) error {
	return nil
}

func (z *zapStd) Options() logger.Options {
	return logger.Options{}
}

func (z *zapStd) Fields(fields map[string]interface{}) logger.Logger {
	//args := make([]interface{}, 0, len(fields))
	//for k, v := range fields {
	//	args = append(args, k)
	//	args = append(args, v)
	//}
	//z.log.With(args...)
	return z
}

func (z *zapStd) Log(level logger.Level, v ...interface{}) {
	switch level {
	case logger.DebugLevel:
		z.log.Debug(v...)
	case logger.InfoLevel:
		z.log.Info(v...)
	case logger.WarnLevel:
		z.log.Warn(v...)
	case logger.ErrorLevel:
		z.log.Error(v...)
	case logger.FatalLevel:
		z.log.Fatal(v...)
	default:
		z.log.Info(v...)
	}
}

func (z *zapStd) Logf(level logger.Level, format string, v ...interface{}) {
	switch level {
	case logger.DebugLevel:
		z.log.Debugf(format, v...)
	case logger.InfoLevel:
		z.log.Infof(format, v...)
	case logger.WarnLevel:
		z.log.Warnf(format, v...)
	case logger.ErrorLevel:
		z.log.Errorf(format, v...)
	case logger.FatalLevel:
		z.log.Fatalf(format, v...)
	default:
		z.log.Infof(format, v...)
	}
}

func (z zapStd) String() string {
	return "zap logger"
}