Categorygithub.com/clearcodecn/log
repositorypackage
1.1.4
Repository: https://github.com/clearcodecn/log.git
Documentation: pkg.go.dev

# README

xLogger

zap based logger

install

  go get github.com/clearcodecn/log@latest

Usage

   import "github.com/clearcodecn/log"
  • add hooks to logger and inject log fields to logger.

    log.AddHook(func(ctx context.Context) Field {
        reqid, ok := ctx.Value("reqid").(string)
        if !ok {
        return Field{}
        }
        return Any("reqid", reqid)
    })
    
    ctx := context.WithValue(context.Background(), "reqid", "123456")
	log.Logger(ctx).Info("help me")
  • gin middleware

var conf xlogger.GinLogConfigure
conf.SkipPrefix("/static","/favico.ico")
conf.AddHeaderKeys("reqid")
gin.Use(log.GinLog(conf))
  • gorm middleware
db := gorm.New()

db.Use(log.NewLoggerPlugin())