diff --git a/log.go b/log.go index 2e88bd1ac0..426e76d083 100644 --- a/log.go +++ b/log.go @@ -20,9 +20,6 @@ import ( "github.com/sirupsen/logrus" ) -const ConnectionIdLogField = "connectionID" -const ConnectTimeLogKey = "connectTime" - func init() { // V quickly checks if the logging verbosity meets a threshold. vtlog.V = func(level glog.Level) glog.Verbose { diff --git a/server/context.go b/server/context.go index 1a04d9ad99..0756b6b306 100644 --- a/server/context.go +++ b/server/context.go @@ -23,7 +23,6 @@ import ( "github.com/opentracing/opentracing-go" "github.com/sirupsen/logrus" - sqle "github.com/dolthub/go-mysql-server" "github.com/dolthub/go-mysql-server/sql" "github.com/dolthub/go-mysql-server/sql/grant_tables" ) @@ -116,8 +115,8 @@ func (s *SessionManager) NewSession(ctx context.Context, conn *mysql.Conn) error } s.sessions[conn.ConnectionID].session.SetLogger( - logger.WithField(sqle.ConnectionIdLogField, conn.ConnectionID). - WithField(sqle.ConnectTimeLogKey, time.Now()), + logger.WithField(sql.ConnectionIdLogField, conn.ConnectionID). + WithField(sql.ConnectTimeLogKey, time.Now()), ) return err @@ -134,6 +133,7 @@ func (s *SessionManager) SetDB(conn *mysql.Conn, db string) error { return sql.ErrDatabaseNotFound.New(db) } + sess.SetLogger(ctx.GetLogger().WithField(sql.ConnectionDbLogField, db)) sess.SetCurrentDatabase(db) return nil } diff --git a/server/handler.go b/server/handler.go index f1a15564dc..f5cc626cb5 100644 --- a/server/handler.go +++ b/server/handler.go @@ -88,7 +88,7 @@ func (h *Handler) NewConnection(c *mysql.Conn) { } c.DisableClientMultiStatements = h.disableMultiStmts - logrus.WithField(sqle.ConnectionIdLogField, c.ConnectionID).WithField("DisableClientMultiStatements", c.DisableClientMultiStatements).Infof("NewConnection") + logrus.WithField(sql.ConnectionIdLogField, c.ConnectionID).WithField("DisableClientMultiStatements", c.DisableClientMultiStatements).Infof("NewConnection") } func (h *Handler) ComInitDB(c *mysql.Conn, schemaName string) error { @@ -149,7 +149,7 @@ func (h *Handler) ConnectionClosed(c *mysql.Conn) { defer h.e.CloseSession(ctx) - logrus.WithField(sqle.ConnectionIdLogField, c.ConnectionID).Infof("ConnectionClosed") + logrus.WithField(sql.ConnectionIdLogField, c.ConnectionID).Infof("ConnectionClosed") } func (h *Handler) ComMultiQuery( diff --git a/sql/log.go b/sql/log.go new file mode 100755 index 0000000000..5b29d56f63 --- /dev/null +++ b/sql/log.go @@ -0,0 +1,21 @@ +// Copyright 2022 Dolthub, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package sql + +const ( + ConnectionIdLogField = "connectionID" + ConnectionDbLogField = "connectionDb" + ConnectTimeLogKey = "connectTime" +) diff --git a/sql/plan/use.go b/sql/plan/use.go index 800bd2e710..c85413e8f9 100644 --- a/sql/plan/use.go +++ b/sql/plan/use.go @@ -68,6 +68,8 @@ func (u *Use) RowIter(ctx *sql.Context, row sql.Row) (sql.RowIter, error) { } ctx.SetCurrentDatabase(dbName) + ctx.SetLogger(ctx.GetLogger().WithField(sql.ConnectionDbLogField, dbName)) + return sql.RowsToRowIter(), nil }