Open wangming1993 opened 6 years ago
package log import ( "context" "os" "go.uber.org/zap" "go.uber.org/zap/zapcore" ) type Logger struct { *zap.SugaredLogger category string fields []interface{} } var logger *Logger func init() { logger = NewLogger("wechat-proxy") } func NewLogger(category string) *Logger { config := zap.NewProductionEncoderConfig() config.MessageKey = "message" encoder := zapcore.NewJSONEncoder(config) core := zapcore.NewCore(encoder, os.Stdout, zap.InfoLevel) return &Logger{ category: category, fields: []interface{}{"type", "service", "category", category}, SugaredLogger: zap.New(core).Sugar(), } } func CtxInfo(ctx context.Context, msg string) { logger.Infow(msg, logger.fields...) }