Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

session: fix user info in general log #34853

Merged
merged 11 commits into from
May 24, 2022
4 changes: 4 additions & 0 deletions parser/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package auth

import (
"fmt"

"github.com/pingcap/tidb/parser/format"
)

Expand Down Expand Up @@ -62,6 +63,9 @@ func (user *UserIdentity) String() string {
// It matches the login user.
func (user *UserIdentity) LoginString() string {
// TODO: Escape username and hostname.
if user == nil {
return ""
}
return fmt.Sprintf("%s@%s", user.Username, user.Hostname)
}

Expand Down
2 changes: 1 addition & 1 deletion session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -3295,7 +3295,7 @@ func logGeneralQuery(execStmt *executor.ExecStmt, s *session, isPrepared bool) {
}
logutil.BgLogger().Info("GENERAL_LOG",
zap.Uint64("conn", vars.ConnectionID),
zap.Stringer("user", vars.User),
zap.String("user", vars.User.LoginString()),
zap.Int64("schemaVersion", s.GetInfoSchema().SchemaMetaVersion()),
zap.Uint64("txnStartTS", vars.TxnCtx.StartTS),
zap.Uint64("forUpdateTS", vars.TxnCtx.GetForUpdateTS()),
Expand Down