From 3fb22944153c8842b88404e1ae5f5e966bd186d9 Mon Sep 17 00:00:00 2001 From: "yong.an" Date: Mon, 13 Jul 2020 18:15:22 +0800 Subject: [PATCH] Revert "accept lunny's suggestion" This reverts commit 57fd6699425bdb97baf6bbeddc3099ffcb4576d8. --- session.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/session.go b/session.go index 709c81f0..7e8b19cb 100644 --- a/session.go +++ b/session.go @@ -100,8 +100,17 @@ func newSessionID() string { } func newSession(engine *Engine) *Session { + var ctx context.Context + var sessionID string + if engine.logSessionID { + sessionID = newSessionID() + ctx = context.WithValue(engine.defaultContext, log.SessionIDKey, sessionID) + } else { + ctx = engine.defaultContext + } + session := &Session{ - ctx: engine.defaultContext, + ctx: ctx, engine: engine, tx: nil, statement: statements.NewStatement( @@ -130,7 +139,7 @@ func newSession(engine *Engine) *Session { sessionType: engineSession, } if engine.logSessionID { - session.ctx = context.WithValue(session.ctx, log.SessionIDKey, session) + session.ctx = context.WithValue(session.ctx, sessionID, session) } return session }