feat: create session. (also print the x-rid into the log)
This commit is contained in:
		@ -26,6 +26,8 @@ import (
 | 
			
		||||
	"os"
 | 
			
		||||
	"sync"
 | 
			
		||||
 | 
			
		||||
	"git.vinchent.xyz/vinchent/howmuch/internal/pkg/core"
 | 
			
		||||
	"git.vinchent.xyz/vinchent/howmuch/internal/pkg/middleware"
 | 
			
		||||
	"go.uber.org/zap"
 | 
			
		||||
	"go.uber.org/zap/zapcore"
 | 
			
		||||
)
 | 
			
		||||
@ -100,6 +102,26 @@ func NewLogger(opts *Options) *zapLogger {
 | 
			
		||||
	return &zapLogger{z: z}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// CtxLog writes context's information into the log
 | 
			
		||||
func CtxLog(ctx core.Context) *zapLogger {
 | 
			
		||||
	return std.CtxLog(ctx)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (z *zapLogger) CtxLog(ctx core.Context) *zapLogger {
 | 
			
		||||
	zz := z.clone()
 | 
			
		||||
 | 
			
		||||
	if rid := ctx.GetHeader(middleware.XRequestID); rid != "" {
 | 
			
		||||
		zz.z = zz.z.With(zap.Any(middleware.XRequestID, rid))
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return zz
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (z *zapLogger) clone() *zapLogger {
 | 
			
		||||
	zz := *z
 | 
			
		||||
	return &zz
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (z *zapLogger) FatalLog(msg string, keyValues ...interface{}) {
 | 
			
		||||
	z.z.Sugar().Fatalw(msg, keyValues...)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user