Used to monitor which DB executed this SQL

This commit is contained in:
yong.an 2020-07-09 16:37:17 +08:00
parent 1a39682180
commit da55c35b25
1 changed files with 8 additions and 2 deletions

View File

@ -101,13 +101,15 @@ func newSessionID() string {
func newSession(engine *Engine) *Session { func newSession(engine *Engine) *Session {
var ctx context.Context var ctx context.Context
var sessionID string
if engine.logSessionID { if engine.logSessionID {
ctx = context.WithValue(engine.defaultContext, log.SessionIDKey, newSessionID()) sessionID = newSessionID()
ctx = context.WithValue(engine.defaultContext, log.SessionIDKey, sessionID)
} else { } else {
ctx = engine.defaultContext ctx = engine.defaultContext
} }
return &Session{ session := &Session{
ctx: ctx, ctx: ctx,
engine: engine, engine: engine,
tx: nil, tx: nil,
@ -136,6 +138,10 @@ func newSession(engine *Engine) *Session {
sessionType: engineSession, sessionType: engineSession,
} }
if engine.logSessionID {
ctx = context.WithValue(engine.defaultContext, sessionID, session)
}
return session
} }
// Close release the connection from pool // Close release the connection from pool