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

Added field for connected db to logger #1014

Merged
merged 2 commits into from
May 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions log.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions server/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
Expand All @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions server/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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(
Expand Down
21 changes: 21 additions & 0 deletions sql/log.go
Original file line number Diff line number Diff line change
@@ -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"
)
2 changes: 2 additions & 0 deletions sql/plan/use.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down