Skip to content

Commit

Permalink
session: fix user info in general log (#34853)
Browse files Browse the repository at this point in the history
close #34852
  • Loading branch information
jackysp committed May 24, 2022
1 parent b08e89e commit 85c595c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions parser/auth/auth.go
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
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

0 comments on commit 85c595c

Please sign in to comment.